49 lines
824 B
C++
49 lines
824 B
C++
#include <iostream>
|
|
using namespace std;
|
|
|
|
class B1 {
|
|
public:
|
|
B1(int i) {
|
|
cout << "constructing B1 " << i << endl;
|
|
}
|
|
~B1() {
|
|
cout << "destructing B1 " << endl;
|
|
}
|
|
};
|
|
|
|
class B2 {
|
|
public:
|
|
static int count;
|
|
int selfCount;
|
|
|
|
public:
|
|
B2() {
|
|
cout << "constructing B2 " << endl;
|
|
count++;
|
|
this->selfCount = count;
|
|
}
|
|
|
|
~B2() {
|
|
cout << "destructing B2, self count: " << this->selfCount << endl;
|
|
}
|
|
};
|
|
|
|
class C : public B2, virtual public B1 {
|
|
public:
|
|
int j;
|
|
B1 memberB1;
|
|
B2 memberB2;
|
|
|
|
public:
|
|
C(int a, int b, int c) : B1(a), memberB1(b), j(c) {
|
|
}
|
|
~C() {
|
|
cout << "destructing c" << endl;
|
|
}
|
|
};
|
|
|
|
int B2::count = 0;
|
|
int main() {
|
|
C obj(1, 2, 3);
|
|
cout << obj.selfCount << endl << obj.memberB2.selfCount << endl;
|
|
} |