← Back to Question List
C++ Code Walkthrough #59
A Temporary Dies at the Semicolon
📄 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 int id() const { return m_id; }10};1112int main() {13 cout << "start" << endl;14 cout << Box(7).id() << endl;15 cout << "middle" << endl;16 Box(8);17 cout << "end" << endl;18 return 0;19}