继承抽象类

#ifndef VIRTUAL1

创新互联公司自2013年创立以来,是专业互联网技术服务公司,拥有项目成都网站制作、做网站、外贸营销网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元安新做网站,已为上家服务,为安新各地企业和个人服务,联系电话:028-86922220

#define VIRTUAL1

#include

using namespace std;

class Number{

public:

Number(int i){ x = i; }

virtual void show() = 0;

protected:

int x;

};

class dec_type :public Number{//这里必须公有继承,否则派生类对象做实参无法传递给基类的

//引用对象。

public:

dec_type(int i) :Number(i){}

void show(){

cout << dec << x<

}

};

class hex_type:public Number{

public:

hex_type(int i) :Number(i){}

void show(){

cout << hex << x<

}

};

class oct_type :public Number{

public:

oct_type(int i) :Number(i){}

void show(){

cout << oct << x<

}

};

#endif

#include"vitual1.h"

void fun(Number &n){//抽象类可以做引用

n.show();

}

int main(){

oct_type oc(50);

fun(oc);//派生类对象做参数传给基类的引用

system("pause");

return 0;

}


新闻名称:继承抽象类
网站网址:http://lszwz.com/article/ggdsis.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款