-
Re: Classes...
@Lindley, I see what your saying. Originally, I had a function their named e.encounter(); but I was trying to minimize the amnout of code i was posting as an example. Let's say that it did have e.encounter(); there instead of e.road(); I know from experience that I would get the exact same error. It doesn't even matter if it's a function or variable. As soon as the compiler sees the "e." it throws up that same error. Is it because the definition is outside of main? I know it works if it's defined in the public class. If i did want to call a class variable or class function outside of public, and outside of main, how would I do that?
-
Re: Classes...
Since you called e.road() in main(), you are already inside the e object. If you wanted to call the same object's encounter() method, you could do
this->encounter();
or simply
encounter();
Both do the same thing.
If you wanted to call the encounter method of a different TextBasedRPG object, you would either need to construct the new object locally in the road() method or pass it in as an argument.
I do wonder if "TextBasedRPG" is really a good class concept. It's a fairly abstract notion. I would expect the classes in a text-based RPG to be more concrete concepts like "Location", "Monster", "Hero", "Weapon", etc.