← Back to Question List
C++ Code Walkthrough #57
Destructor Order With a Nested Block
📄 Code
Read carefully — what does this print?1#include <iostream>2using namespace std;34class Box {5 int m_id;6public:7 Box(int id) : m_id(id) { cout << "Create " << m_id << endl; }8 ~Box() { cout << "Destroy " << m_id << endl; }9};1011int main() {12 Box a(1);13 {14 Box b(2);15 cout << "inside" << endl;16 }17 Box c(3);18 cout << "end" << endl;19 return 0;20}