当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - Defining an object of a subclass

问题描述:

I am trying to construct a class with three subclasses, and then creating an object of these subclasses. This is what I am doing so far,

 class Car{

class Red{

public:

... //functions

};

class Blue{

public:

... //functions

};

class Red{

public:

... //functions

};

};

I am having trouble creating an object of the class red. I tried doing this:

Car*redCar;

redCar = new Red;

But it does not work. Any ideas?

网友答案:
Car::Red redCar;

Assuming that Red is public.

Get a book on C++!

分享给朋友:
您可能感兴趣的文章:
随机阅读: