c++ - Why do I get an error trying to call a template member function with an explicit type parameter? -
i don't it, seems me call f
unambiguous, fails compile expected primary-expression before ‘int’
. if comment out line call f
, compiles fine.
template<typename t> struct { template<typename s> void f() { } }; template<typename t> struct b : a<t> { void g() { this->f<int>(); } };
this due obscure provision of standard in if have template tries access template function in object type depends on template argument, have use template
keyword in weird way:
this->template f<int>();
this similar weirdness typename
comes dependent types, except applied functions. in particular, if leave out template
keyword, there's parsing ambiguity between
this->f<int>()
(what intended), and
((this->f) < int) > ()
which makes no sense (hence error). use of keyword template
here disambiguates , forces compiler recognize it's looking @ valid call templated member function rather garbled mass of symbols.
hope helps!
Comments
Post a Comment