#include <iostream>
using namespace std;
class parent
{
int i;
protected:
int x;
public:
parent() { x = 0; i = 0; }
void change() { x++; i++; }
void display();
};
class son :public parent
{
public:
void modify();
};
void parent::display() { cout << "x=" << x << endl; }
void son::modify() { x++; }
int main()
{
son s; // 由于son没有提供default constructor,而父类含有constructor,那么编译器将合成有用的default constructor,以调用父类ctor
parent p;// 调用ctor
s.display();// x=0
s.change();// 此时son对象s中的x==1,i==1
s.modify();// 此时son对象s中的x==2,i==1
s.display();// x=2
p.change();// 此时parent对象p中的x==1, i==1
p.display();// x=1
cin.get();
}