CJCoding With Joseph
15free / daySign inCreate account
Back to Code Walkthrough

Constructor and Destructor Order

C++ code walkthrough · Question 3
hardClasses

Code

Read carefully. What does this print?
1#include <iostream>
2using namespace std;
3 
4class Box {
5public:
6 int id;
7 Box(int i) : id(i) {
8 cout << "Create " << id << endl;
9 }
10 ~Box() {
11 cout << "Destroy " << id << endl;
12 }
13};
14 
15int main() {
16 Box a(1);
17 Box b(2);
18 return 0;
19}

Your answer