C++含参数函数的继承方法

嵌入式系统 时间:2016-12-01来源:网络
方法:先继承类然后映射函数。

#include

class animal
{
public:
animal(char thename);

};

animal::animal(char thename)
{
char name;
cout<}

class pig:public animal //先继承类,并在次写上子类映射函数
{
public:
pig(char thename);
};

pig::pig(char thename):animal(thename) //后映射函数。注意父类函数此时无需再定义数据类型
{
}

class turtle:public animal
{
public:
turtle(char thename);
};

turtle::turtle(char thename):animal(thename)
{
}
int main()
{
pig st(M);
turtle sm(n);
return 0;
}

关键词: C++含参数函数继承方

加入微信
获取电子行业最新资讯
搜索微信公众号:EEPW

或用微信扫描左侧二维码

相关文章

查看电脑版