CJCoding With Joseph
15free / daySign inCreate account
โ† Back to Question List
C++ Code Walkthrough #3

Constructor and Destructor Order

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