← Back to Question List
C++ Code Walkthrough #60
Members Are Built Before the Body and Destroyed After
📄 Code
Read carefully — what does this print?1#include <iostream>2using namespace std;34class Engine {5public:6 Engine() { cout << "Engine" << endl; }7 ~Engine() { cout << "~Engine" << endl; }8};910class Wheel {11public:12 Wheel() { cout << "Wheel" << endl; }13 ~Wheel() { cout << "~Wheel" << endl; }14};1516class Car {17 Wheel m_wheel;18 Engine m_engine;19public:20 Car() : m_engine(), m_wheel() { cout << "Car" << endl; }21 ~Car() { cout << "~Car" << endl; }22};2324int main() {25 Car c;26 cout << "driving" << endl;27 return 0;28}