mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-04-24 02:40:52 +08:00
support bazel complie this project and format code.
This commit is contained in:
33
practical_exercises/10_day_practice/day5/virtual/seq.cpp
Normal file
33
practical_exercises/10_day_practice/day5/virtual/seq.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/* 虚基类调用次序(重要).cpp */
|
||||
//重要!!!
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
class A {
|
||||
int a;
|
||||
|
||||
public:
|
||||
A() { cout << "Constructing A" << endl; }
|
||||
};
|
||||
class B {
|
||||
public:
|
||||
B() { cout << "Constructing B" << endl; }
|
||||
};
|
||||
class B1 : virtual public B, virtual public A {
|
||||
public:
|
||||
B1(int i) { cout << "Constructing B1" << endl; }
|
||||
};
|
||||
class B2 : public A, virtual public B {
|
||||
public:
|
||||
B2(int j) { cout << "Constructing B2" << endl; }
|
||||
};
|
||||
class D : public B1, public B2 {
|
||||
public:
|
||||
D(int m, int n) : B1(m), B2(n) { cout << "Constructing D" << endl; }
|
||||
A a;
|
||||
};
|
||||
|
||||
int main() {
|
||||
D d(1, 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user