我试图理解为什么(使用gcc 4.8.2)以下代码不能编译:调用模板函数成员时,它的名字叫同一个名字
struct A {
template <typename T>
T f() {return T(0);}
};
struct B : A {
using MyT = int;
MyT f() {return (A *)this->template f<MyT>();}
};
int main()
{
B b;
std::cout << b.f() << std::endl;
return 0;
}
如果我改变从f
名称在基地f1
,那么下面编译就好:
struct A {
template <typename T>
T f1() {return T(0);}
};
struct B : A {
using MyT = int;
MyT f() {return this->template f1<MyT>();}
};
运算符优先级。 –
要扩展@ T.C.的评论:'return static_cast (this) - > template f();' –