【发布时间】:2013-02-18 09:53:25
【问题描述】:
使用此设置:
template<int N>
struct Base {
void foo();
};
class Derived : Base<1> {
static void bar(Derived *d) {
//No syntax errors here
d->Base<1>::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
有什么区别?为什么第二种会导致语法错误?
【问题讨论】:
-
你用的是什么编译器?
-
该死,错字。这个问题很垃圾。
标签: c++ templates token-name-resolution