← Back to archive

Stdle #132 · raii · 2026-10-16

What does this C++ snippet output?

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

#include <iostream>
struct Once {
Once() { std::cout << "init\n"; }
};
Once& instance() {
static Once o;
return o;
}
int main() {
std::cout << "before\n";
instance();
instance();
std::cout << "after\n";
}
RAII
3 lines
4 attempts left

Answer & explanation