← Back to archive

Stdle #35 · virtual · 2026-07-11

What does this C++ snippet output?

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

#include <iostream>
struct A {
virtual void f() { std::cout << "A\n"; }
void call() { this->f(); }
};
struct B : A {
void f() override { std::cout << "B\n"; }
};
int main() {
B b;
static_cast<A&>(b).call();
}
Virtual
4 attempts left

Answer & explanation