Created
August 13, 2018 11:30
-
-
Save Rivares/bfea63945e35b2d50dd48ab7fd251e7c to your computer and use it in GitHub Desktop.
Example work of constructor
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> | |
struct A | |
{ | |
A() { std::cout << "A constructed successfully\n"; } | |
~A(){ std::cout << "A destroyed\n"; } | |
}; | |
struct B | |
{ | |
A a1, a2, a3; | |
B() { std::cout << "B constructed successfully\n"; } | |
~B(){ std::cout << "B destroyed\n"; } | |
}; | |
struct C : A, B | |
{ | |
C() { std::cout << "C constructed successfully\n"; } | |
~C(){ std::cout << "C destroyed\n"; } | |
}; | |
int main () | |
{ | |
C c; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
A constructed successfully
A constructed successfully
A constructed successfully
A constructed successfully
B constructed successfully
C constructed successfully
C destroyed
B destroyed
A destroyed
A destroyed
A destroyed
A destroyed