Hmm.. I'm slighty confused, but perhaps you're thinking of a static member?
It would sorta work like this:
class CShip {
public:
// ....
static int maxCargo;
};
Then for each class you can set this variable, and it will remain the same throughout all instances of the classes.
The tricky part is where you derive your classes. You could simply override the variable each time you derive from the class. It might not be the best way of doing it, but if you left it as it was in the base class, it would remain the same not only throughout all instances of CShip but the value would also be the same in CMedShip and CLargeShip . Not what you want if I understood you correctly.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Thanks for the reply..
the maxCargo wasnt really an issue...
maybe if i explain it alittle better...
Sorry, I misunderstood you! You may want to use vectors instead of arrays; you can dynamically add and remove to them. So you could have something like:
void Cargo::addCargo(string newCargo) {
name.push_back(newCargo);
}
Of course, if the cargo class contains more than simply a name, it might be a better idea to make a vector of the entire class, and not of individual members. However, the idea is the same, except that the vectors would be controlled by Ship instead of ShipCargo .
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339