引用的方式覆盖
#include "iostream"
using namespace std;
class base
{
public:
base() {}
base(int a, int b) : a(a), b(b)
{
}
int a;
int b;
};
class step1 : public ::base
{
public:
step1() {}
};
int main()
{
step1 rlxy;
rlxy.a = 100;
rlxy.b = 200;
cout << rlxy.a << endl;
cout << rlxy.b << endl;
base &ccc = rlxy;
cout << ccc.a << endl;
cout << ccc.b << endl;
}
赋值的方式覆盖
#include "iostream"
using namespace std;
class base
{
public:
base() {}
base(int a, int b) : a(a), b(b)
{
}
int a;
int b;
};
class step1 : public ::base
{
public:
step1() {}
};
int main()
{
step1 rlxy;
rlxy.a = 100;
rlxy.b = 200;
cout << rlxy.a << endl;
cout << rlxy.b << endl;
base ccc = rlxy;
cout << ccc.a << endl;
cout << ccc.b << endl;
}