Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumC++CRTPSingle-choice MCQ

A common CRTP pitfall: what subtle bug exists if you write the base as `struct Base : Counter<Base>` instead of giving each derived type its own instantiation, when Counter<T> holds a `static int count;` to count instances per type?

template <class T> struct Counter { static int count; Counter() { ++count; } }; template <class T> int Counter<T>::count = 0; struct A : Counter<A> {}; struct B : Counter<B> {};