专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

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

作者:黄波海   来源:本站原创   点击数:  更新时间:2014年03月06日   【字体:

方法:先继承类然后映射函数。
#include <iostream.h>

class animal
{
public:
animal(char thename);

};

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

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

 

关闭窗口

相关文章