Back to Code Walkthrough
Constructor and Destructor Order
C++ code walkthrough · Question 3Code
Read carefully. What does this print?1#include <iostream>2using namespace std;34class 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};1415int main() {16 Box a(1);17 Box b(2);18 return 0;19}