C++ 如何从模板化派生类上的模板化基类调用成员?
使用此设置:C++ 如何从模板化派生类上的模板化基类调用成员?,c++,templates,token-name-resolution,C++,Templates,Token Name Resolution,使用此设置: template<int N> struct Base { void foo(); }; class Derived : Base<1> { static void bar(Derived *d) { //No syntax errors here d->Base<1>::foo(); } }; 有什么区别?为什么第二个会导致语法错误?在代码在Clang 3.2(请参阅)和GCC
template<int N>
struct Base {
void foo();
};
class Derived : Base<1> {
static void bar(Derived *d) {
//No syntax errors here
d->Base<1>::foo();
}
};
有什么区别?为什么第二个会导致语法错误?在代码在Clang 3.2(请参阅)和GCC 4.7.2(请参阅)上编译良好的前提下,我看不出使用
Base:
:只需使用d->foo()
:
你在用什么编译器?该死的,打字错误。这个问题是垃圾。
template<class E>
struct Base {
void foo();
};
template<class E>
class Derived : Base<E> {
static void bar(Derived<E> *d) {
//syntax errors here
d->Base<E>::foo();
}
};
error: expected primary-expression before '>' token
error: '::foo' has not been declared
template<class E>
struct Base {
void foo() { }
};
template<class E>
struct Derived : Base<E> {
static void bar(Derived<E> *d) {
//syntax errors here
d->foo();
}
};
int main()
{
Derived<int> d;
Derived<int>::bar(&d);
}
d->template Base<E>::foo();