Skip to content

Instantly share code, notes, and snippets.

@Rivares
Created August 13, 2018 11:30
Show Gist options
  • Save Rivares/bfea63945e35b2d50dd48ab7fd251e7c to your computer and use it in GitHub Desktop.
Save Rivares/bfea63945e35b2d50dd48ab7fd251e7c to your computer and use it in GitHub Desktop.
Example work of constructor
#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;
}
@Rivares
Copy link
Author

Rivares commented Aug 13, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment