c++ - Use of "template<>" for static members -
i came across code has confused me. have distilled confusion down simple case
template<typename t> struct s { t member; static const size_t size; }; struct u { int i; }; typedef s<u> us_t; template<> const size_t us_t::size = sizeof(u);
q1: why need "template<>
" on last line, since us_t
described?
the code came across - compiles - has equivalent of this:
template<>template<> const size_t us_t::size = sizeof(u);
i'm pretty sure cut-and-paste error wasn't caught because compiled. q2: valid? if so, why? [i notice codepad.org compile code "template<>template<>
".]
imagine typedef macro that's expanded @ compile time instead of pre-processor time.
then without template<>
you'd have
const size_t s<u>::size = sizeof(u);
and that's not valid syntax, because you're doing template specialization
Comments
Post a Comment