Reputation: 97601
With this setup:
template<int N>
struct Base {
void foo();
};
class Derived : Base<1> {
static void bar(Derived *d) {
//No syntax errors here
d->Base<1>::foo();
}
};
Everything works fine. However, with this example:
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();
}
};
I get:
error: expected primary-expression before '>' token
error: '::foo' has not been declared
What's the difference? Why does the second cause a syntax error?
Upvotes: -1
Views: 63
Reputation: 126452
With the premise that your code compiles fine on Clang 3.2 (see here) and GCC 4.7.2 (see here), I do not see a reason for using Base<E>::
: just use d->foo()
:
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);
}
Alternatively, you could try using the template
disambiguator:
d->template Base<E>::foo();
Upvotes: 1