Before C++17, a static const int member with an in-class initialiser still required what, if it was odr-used?
Correct answer
B. An out-of-class definition, because the in-class initialiser served only as a declaration for such uses
16 views
B. An out-of-class definition, because the in-class initialiser served only as a declaration for such uses
16 views
odr-use, meaning taking the address or binding a reference, required a separate definition such as const int T::k; outside the class, even though the in-class initialiser allowed use in constant expressions. C++17 introduced inline variables, so a static constexpr member is now implicitly inline and self-defining. Forgetting the definition produced the classic undefined reference linker error.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is B? Ask here and get an explanation.