Time Limit: 1sec Memory Limit:256MB
Description
The class Human is defined as follows:
class Human {
public:
virtual string getSkinColor() = 0;
};
You are to derive two classes European and African from Human, with the skin colors "white" and "black" respectively.
Your submitted source code should include the whole implementation of the classes European and African, but without the class Human.
No main() function should be included.
class European : public Human
{
public:
virtual string getSkinColor() { return "white"; }
};
class African : public Human
{
public:
virtual string getSkinColor() { return "black"; }
};
请记得及时采纳
点我回答右边的采纳即可。
楼主,难道你觉得这题有陷阱嘛?就是一个考察基类纯虚函数在子类中的实现啊
使用了纯虚函数。
如果一个类中,只有一部分纯虚函数,相当于java的抽象类,需要子类来继承;
如果一个类中,全部是纯虚函数,外加上数据成员是public,相当于java的接口,必须实现。
java类只能单继承,接口可多继承。
C++因为简化了,什么都可
基类纯虚函数在子类中的实现