← Back to archive

Stdle #83 · raii · 2026-08-28

What does this C++ snippet output?

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

#include <iostream>
#include <vector>
struct M {
M() { std::cout << "ctor\n"; }
M(M&&) noexcept { std::cout << "move\n"; }
M(const M&) { std::cout << "copy\n"; }
~M() { std::cout << "dtor\n"; }
};
int main() {
std::vector<M> v;
v.reserve(2);
v.push_back(M{});
std::cout << "one\n";
}
RAII
5 lines
4 attempts left

Answer & explanation