下面这个代码为什么打印顺序是这样子的?萌新提问!
#include<iostream>
using namespace std;
class Base
{
private:
int b;
public:
Base(int c);
~Base();
};
Base::Base(int c)
{
b=c;
cout<<"Base "<<b<<" says hello"<<endl;
}
Base::~Base()
{
cout<<"Base "<<b<<" says goodbye"<<endl;
}
class Derived:public Base
{
private:
int d;
public:
Derived(int c,int b):Base(c)
{
d=b;
cout<<"Derived "<<d<<" says hi"<<endl;
}
~Derived()
{
cout<<"Derived "<<d<<" says bye"<<endl;
}
};
int main()
{
int a,b;
cin>>a>>b;
Derived dr(a,b);
return 0;
}