← Back to archive

Stdle #46 · raii · 2026-07-22

What does this C++ snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

#include <iostream>
struct Base {
Base() { std::cout << "Base ctor\n"; }
~Base() { std::cout << "Base dtor\n"; }
};
struct Derived : Base {
Derived() { std::cout << "Derived ctor\n"; }
~Derived() { std::cout << "Derived dtor\n"; }
};
int main() {
Derived d;
}
RAII
4 lines
4 attempts left

Answer & explanation