c++ - Specializing a base class' member function in a derived class template -
have @ code:
struct foo { virtual int bleh() { return 42; } }; template<typename t> struct bar : public foo { }; // error template<> int bar<char>::bleh() { return 12; }
i'm trying provide definition of base::bleh
bar<char>
, compiler(gcc 4.7.2) rejects code following diagnostic:
template-id ‘bleh<>’ ‘int bar<char>::bleh()’ not match template declaration
it seems base::bleh
somehow hidden in bar
. i've fixed using following definition in bar
:
template<typename t> struct bar : public foo { // doesn't work //using foo::bleh; // works int bleh() { return foo::bleh(); } };
but i'm curious of why fails compile. why compiler rejecting code?
in non-compiling example, you're attempting specialize , define function hasn't been declared in template definition of bar
... in later example have declared defined non-specialized version of function inside template definition of bar
, why compiles. can tell, here associated language in standard concerning why first version won't compile (14.7.3/4):
a member function, member function template, member class, member enumeration, member class template, or static data member of class template may explicitly specialized class specialization implicitly instantiated; in case, definition of class template shall precede explicit specialization member of class template
Comments
Post a Comment