fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A {
  5. public:
  6. int test;
  7. A(string text = "Constructor A") { cout << text << endl; }
  8. };
  9.  
  10. class B: virtual public A {
  11. public:
  12. B(): A("A called from B") { cout << "Constructor B" << endl; }
  13. };
  14.  
  15. class C : virtual public A {
  16. public:
  17. C() : A("A called from C") { cout << "Constructor C" << endl; }
  18. };
  19.  
  20. class D : public B, public C {
  21. public:
  22. D() { cout << "Constructor D" << endl; }
  23. };
  24.  
  25. int main() {
  26. D d;
  27. cout << &d.B::test <<endl;
  28. cout << &d.C::test <<endl;
  29. cout <<&d.test<<endl;
  30. return 0;
  31. }
Success #stdin #stdout 0s 4340KB
stdin
Standard input is empty
stdout
Constructor A
Constructor B
Constructor C
Constructor D
0x7ffdd3e1c980
0x7ffdd3e1c980
0x7ffdd3e1c980