Are there such a thing?
I am wanting to create a class "car" that contains many classes. Could I do this, if so how.
I would like to address it like car.engine.size()
Printable View
Are there such a thing?
I am wanting to create a class "car" that contains many classes. Could I do this, if so how.
I would like to address it like car.engine.size()
Yep, something like -
Code:class car
{
public:
class engine
{
public:
int hp;
int cc;
}the_engine;
//more stuff
};
int main()
{
car beast;
beast.the_engine.hp=15000;
return 0;
}
Thanks, I thought it might be something like that
i don't think so sorenson, it'd be more like this:
what you did may work, but i prefer doing it this way.Code:class engine
{
public:
int hp, cc /*etc.*/;
}
class car
{
public:
engine theEngine;
//other stuff.
}
>what you did may work, but i prefer doing it this way
Of course it'll work. If engines are only used within cars then I see no reason not to do what I have done, as long as engine is a simple class and they are only required by cars, it would be possible to prevent orphaned engines being created.