不明白以下结果是怎么出来的,请求分析过程。康桑阿米达

#include
using namespace std;
class Base
{
friend void fun();
public:
Base(int data = 0)
:b(data)
{
cout << "Base()" << endl;
}
~Base()
{
cout << "~Base()" << endl;
}
static void show()
{
cout << "static show()" << endl;
}
void add()
{
a++;
}
static int a;
private:
int b;
};
int Base::a = 0;
class Derive :public Base
{
public:
Derive(int data = 0)
:d(data)
{
cout << "Derive()" << endl;
}
~Derive()
{
cout << "~Derive()" << endl;
}
void Add()
{
a++;
}
private:
int d;
};

int main()
{
Derive d;
d.show();
d.a = 2;
d.add();
d.Add();
cout << d.a << endl;
return 0;
}

Base()
Derive()
static show()
4
~Derive()
~Base()

前两个输出应该没问题吧(基类的构造函数函数优先被调用,和析构正好相反)
子类不能从父类继承的有:
1. 构造函数
2. 拷贝构造函数
3. 析构函数
子类和父类是共享一个静态成员变量的(不是继承,因为静态成员是没有this指针的,是继承不过来的)
所以打印出4应该能理解了吧

前两个和后两个的输出容易理解,构造函数和析构函数的执行顺序相反

d.add()和d.Add()里各有个a++,a=2执行了两次a++,a就变成了4,没什么好讲的,你还有不懂的说出来