May 23rd, 2009, 11:03 AM
Including a class within another class
I'm still very new to C++ so apologies in advance if I am not too clear in my description of my problem.
I am making a text based drug dealing game which has an Class called Enemy which contains all the information you might expect to find about an enemy (health and weapon stats). This is defined in a .h and .cpp file within my project. I am then making a class called Location which contains information on how many customers want drugs of each type, the maximum number of customers for each drug type and so on. At each location I want to have an array of enemies so that the player must fight off a group of enemies before they can start to deal on that turf.
So I have my Enemy class working properly and then within the Location class I want to add something like this:
So I have an array of five enemies which I can then tweak each turn based on some simple randomisation so the gang is not always identical.
When I compile this within Code::Blocks I get the following error.
`Enemy' does not name a type
I have written #include "Enemy.h" at the top of the Location.h file so it should know what an Enemy class is. What am I doing wrong?
#endif // LOCATION_H_INCLUDED
I'd like to make an array of Locations that would be my map and I would access the enemy gang thus.
locations.enemies.name = "Gangster1";
Am I doing something fundamentally wrong? Can you not include a predefined class within another class?
Any help would come as a great relief!
Thanking you in advance.
Last edited by Diamo; May 23rd, 2009 at 02:18 PM.
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!