← Back to archive

Stdle #17 · raii · 2026-06-23

What does this C++ snippet output?

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

#include <iostream>
#include <vector>
struct Noisy {
int id;
Noisy(int i) : id(i) { std::cout << "ctor " << id << "\n"; }
~Noisy() { std::cout << "dtor " << id << "\n"; }
};
int main() {
std::vector<Noisy> v;
v.reserve(2);
v.emplace_back(1);
v.emplace_back(2);
v.pop_back();
std::cout << "popped\n";
}
RAII
5 lines
4 attempts left

Answer & explanation