📄 13_2.cpp
字号:
#include<iostream.h>
class base
{
int x,y;
public:
base(int i,int j){x=i;y=j;}
virtual int add(){return x+y;}
};
class two:public base
{
public:
two(int i,int j):base(i,j){}
int add(){return base::add();}
};
class three:public base
{
int z;
public:
three(int i,int j,int k):base(i,j)
{
z=k;
}
int add()
{
return (base::add()+z);
}
};
void disp(base *obj)
{
cout<<"参数相加:"<<obj->add()<<endl;
}
void main()
{
two *p=new two(10,20);
three *q=new three(10,20,30);
cout<<"输出结果为:"<<endl;
disp(p);
disp(q);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -