锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

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

时间:2024-05-06 06:37:12

方法:先继承类然后映射函数。
#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;
}


-电子元器件采购网(www.ruidan.com)是本土元器件目录分销商,采用“小批量、现货、样品”销售模式,致力于满足客户多型号、高质量、快速交付的采购需求。 自建高效智能仓储,拥有自营库存超过50,000种,提供一站式正品现货采购、个性化解决方案、选型替代等多元化服务。
锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章