📄 b_9_2.cpp
字号:
#include "stdafx.h"
#include <iostream>
#include <string>
#include<iomanip>
using namespace std;
class A {
public:
int va;
A() {va = 0;}
A(int i){va=i;}
virtual A& operator+(A& t)
{ static A temp(0);
temp.va = va + t.getval();
return temp;
}
virtual A& operator=(A& t)
{ va=t.getval();
return *this;
}
virtual int getval(){return va;}
void disp(){cout<<"va="<<va<<endl;}
};
class B:public A {
public:
int vb;
B() {vb = 0;}
B(int i){vb=i;}
virtual A& operator+(A& t)
{ static B temp(0);
temp.vb = vb + t.getval();
return temp;
}
virtual A& operator=(A& t)
{ vb=t.getval();
return *this;
}
virtual int getval(){ return vb;}
void disp(){cout<<"vb="<<vb<<endl;}
};
class C:public B {
public:
int vc;
C() { vc = 0;}
C(int i){vc=i;}
virtual A& operator+(A& t)
{ static C temp(0);
temp.vc = vc + t.getval();
return temp;
}
virtual A& operator=(A& t)
{ vc=t.getval();
return *this;
}
virtual int getval(){return vc;}
void disp(){cout<<"vc="<<vc<<endl;}
};
void main()
{ A a(10);
B b(20);
C c(60);
a=b+c;
c=b+a;
a.disp();
b.disp();
c.disp();
cin.get(); //等待结束,以便调测程序,可以删除
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -