新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > C++含参数函数的继承方法

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

作者:时间:2016-12-01来源:网络收藏
方法:先继承类然后映射函数。

#include

本文引用地址:http://www.eepw.com.cn/article/201612/324433.htm

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;
}



评论


相关推荐

技术专区

关闭