Created
August 31, 2017 15:12
-
-
Save mcleary/89921275cab7d4493a948260a2d910b4 to your computer and use it in GitHub Desktop.
Shows that the order in which constructor of classes with multiple inheritance is defined by the declaration in the header file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class BaseClass1 | |
{ | |
public: | |
BaseClass1() | |
{ | |
cout << "Base class 1 constructor" << endl; | |
} | |
BaseClass1(int param) | |
{ | |
cout << "Base class 1 constructor with param" << endl; | |
} | |
}; | |
class BaseClass2 | |
{ | |
public: | |
BaseClass2() | |
{ | |
cout << "Base class 2 constructor" << endl; | |
} | |
}; | |
class DerivedClass : public BaseClass2, public BaseClass1 | |
{ | |
public: | |
DerivedClass() : | |
BaseClass1(10), | |
BaseClass2() | |
{ | |
cout << "Derived class constructor" << endl; | |
} | |
}; | |
int main() | |
{ | |
DerivedClass dc; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment