No, it's code, thus should be inside a function, and function implementations should be inside .cpp files.
But you can put those into a separate .cpp file if you believe it helps.
Ok then, how about
I would like to move this into my classes.h like thisCode:Room *location;
but it says it is expecting a ; before * when I move it to my classes.hCode:class User { public: void vSetUserName(string); //Function for setting the username, takes a string void vSetAge(int); //Function for setting the age, takes an int string sGetUserName() const; //Function for retrieving the username int iGetAge() const; //Function for retrieving the age Room *location;
Did you include proper header file for Room before?
If yes, then I would check to see if User class header includes another header which includes the user class header again. That can cause all sorts of problems.
And just as a FYI, you can also type Room *location as Room* location.
You know a little of pointers, I hope?
Yeah I know the basics of most the topics I just have come across some more indepth stuff which I havnt come across yet so its taking a bitl onger to process.
main.cpp includes classes.h
storyone.cpp includes classes.h
pets.cpp includes classes.h
user.cpp includes classes.h
Will that be the problem?
and yeah I knew you could do that
The .cpp files includes are not a problem. But what about the includes of the headers themselves?
They may have circular dependencies, unless you actually forgot to include the proper header that declares the class Room.
And because I loves FYIs, here's another one
Stroustrup: C++ Style and Technique FAQ
Ha, I think I have fixed it.
I had the Room class AFTER the Player Class so I think the room *location practically didnt mean anything
Is there anyway to make a class kind of... global? lol.
I want to have a cpp file with a single function in it called storyone.cpp
but I cant compile it because it is saying NewUser (Which is a defined class) isnt declared within this scope.
Yes, it is possible to make global variables, but you should be careful with them.
Put the variable inside ONE .cpp file, ie: int x = 55;
Then put the same declaration inside a header file with extern before: extern int x;
As long as you include header, it will compile.
Ahh I see. Thats clever. Why the careful ness? is it dangerous?
and does that one variable inside the .cpp file have to be global? or can it be within a function ?
Can I also do it with a class? Like I have the class made in my main as the user enters his name etc and then access the class for the movement within another file?
Or should i take the names of the user put it into a global variable and define the user in the other file
P:\KOA_DM_IT\KOA_DM_IT\story1.h|69|error: `NewUserlocation' was not declared in this scope|
Which is this line
but I have this..Code:NewUser.location = NewUserlocation->north;
Code:NewUser.location = &rooms[0];
Last edited by Aliaks; 07-14-2009 at 05:36 AM.
But surely this should be it
which I have in the functionCode:NewUser.location = &rooms[0];