So, I've been making a textRPG game, when the school started I scrapped the project because I don't have that much free time now, but recently I found the project and decided to continue (i just wasted your time by telling this retarded back-story :D) so anyway I started work on the battle system and got into a bit of trouble, I can't (and don't know how to) use one instance of a class in multiple functions/files. I've attached the source code below. Also any advice on the game would be helpful.
Here is my game Multiupload.com - upload your files to multiple file hosting sites!, for some odd reason, file uploader doesn't work.
4 replies to this topic
#1
Posted 22 January 2011 - 08:13 AM
|
|
|
#2
Posted 22 January 2011 - 02:12 PM
You may use a global variable if you'd like. However, many call global variables satanic devices so you might also just want to structure your program in such a way that all objects that need references to the variable have one. Take a look at the following code for what I mean on the second part
class God
{
public:
void foo() { return; }
};
class Dog
{
public:
void bar() { return; }
};
class Priest
{
God & god_;
public:
Priest(God & zgod) : god_(zgod) { /* void */ }
void pray() { god_.foo(); }
};
#3
Posted 23 January 2011 - 03:00 AM
Umm, and how do I make a global instance?
#4
Posted 23 January 2011 - 11:57 AM
#5
Posted 24 January 2011 - 04:16 AM
Ok, i added Player Hero before my main function, but i stll get an error about it being a declared variable, because "Player Hero" is in another file maybe?
EDIT: OK problem i solved the problem myself, but thanks for help. All i needed was to declare instance in main function then in other files use extern
EDIT: OK problem i solved the problem myself, but thanks for help. All i needed was to declare instance in main function then in other files use extern
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









