Description
There are four classes A, B, C and D. They all have the same form as follows:
class X
{
public:
X() { cout << "In X()" << endl; }
~X() { cout << "In ~X()" << endl; }
};
X belongs to { A, B, C, D }. These four classes have some kind of inheritance relationship. You are to find the right one to generate the desired output, which should come from the constructors and destructors.
Your submitted source code should include all the implementation of the A, B, C and D classes.
No main() function should be included.
Note:
the main() function of the test framework looks like this:
int main()
{
D d;
return 0;
}
Input
Output
In B()
In C()
In B()
In A()
In D()
In ~D()
In ~A()
In ~B()
In ~C()
In ~B()
source.h
#include<iostream>
using namespace std;
class B
{
public:
B() { cout << "In B()" << endl; }
~B() { cout << "In ~B()" << endl; }
};
class A:public B
{
public:
A() { cout << "In A()" << endl; }
~A() { cout << "In ~A()" << endl; }
};
class C:public B
{
public:
C() { cout << "In C()" << endl; }
~C() { cout << "In ~C()" << endl; }
};
class D:public C,public A
{
public:
D() { cout << "In D()" << endl; }
~D() { cout << "In ~D()" << endl; }
};
framework.cpp
#include <iostream>
using namespace std;
#include "source.h"
int main()
{
// freopen("test01.in", "r", stdin);
// freopen("test01.out", "w", stdout);
D d;
return 0;
}