c++ - Need scope resolution operator to call member function template when class template exists with same name -
i have class template happens have same name member function template of classes. function template gets instantiated 1 of classes member function template in question. call member function template within function template need use template
keyword, understand , have no problem that. however, need use scope resolution operator (i found out that's that's called) ::
specify mean class' member function template , not class template , don't understand why.
that's lot of templated things let me give example:
//class same name member function below. //must class template or error doesn't show up. //also no error if function template instead of class template <class t> struct f { }; struct base { //function same name struct above, //no error if not templated template <int n> void f(){} }; //template function instantiated t=base. //no error if not templated template <class t> void g(t t) { //i understand why template keyword needed here, //but not why t:: needed t.t::template f<0>(); //t.template f<0>(); gives error. }
the error in question (from g++-4.7)
error: type/value mismatch @ argument 1 in template parameter list ‘template<class t> struct f’ error: expected type, got ‘0’
it seems compiler parses f<0>()
on commented out line (without scope resolution operator) trying instantiate object of type struct f<0>
. don't know why doing this, thought should able see t.template
i'm trying access member function template.
i'd understand going on here, why t::
needed in case, other placate compiler?
it seems there no problem under msvc , clang, seems g++-specific issue.
i think has two phase lookup. steve jessops notes in answer are important.
Comments
Post a Comment