L
Lawrence Spector
I ran into a problem using g++. Visual Studio 2005 never complained
about this, but with g++ I ran into this error. I can't figure out if
I've done something wrong or if this is a compiler bug. Here's a very
simple example which should illustrate what I'm doing.
#include <iostream>
template <class T>
class TestBase
{
public:
TestBase() {}
int testMethod()
{
return T::callMethod<int>(); // ERROR?
}
};
class Derived : public TestBase<Derived>
{
public:
Derived() : TestBase<Derived>() {}
template <class T>
T callMethod()
{
return T();
}
};
int main()
{
Derived derived;
int x = derived.callMethod<int>();
int y = derived.testMethod(); // CALLED FROM HERE
return 0;
}
Results in the following:
$ g++ -c GccTemplateCompile.cpp
GccTemplateCompile.cpp: In member function `int
TestBase<T>::testMethod()':
GccTemplateCompile.cpp:12: error: expected primary-expression before
"int"
GccTemplateCompile.cpp:12: error: expected `;' before "int"
GccTemplateCompile.cpp:12: error: expected primary-expression before
"int"
GccTemplateCompile.cpp:12: error: expected `;' before "int"
Does anyone have any idea what's going on?
Thanks in advance,
Lawrence
about this, but with g++ I ran into this error. I can't figure out if
I've done something wrong or if this is a compiler bug. Here's a very
simple example which should illustrate what I'm doing.
#include <iostream>
template <class T>
class TestBase
{
public:
TestBase() {}
int testMethod()
{
return T::callMethod<int>(); // ERROR?
}
};
class Derived : public TestBase<Derived>
{
public:
Derived() : TestBase<Derived>() {}
template <class T>
T callMethod()
{
return T();
}
};
int main()
{
Derived derived;
int x = derived.callMethod<int>();
int y = derived.testMethod(); // CALLED FROM HERE
return 0;
}
Results in the following:
$ g++ -c GccTemplateCompile.cpp
GccTemplateCompile.cpp: In member function `int
TestBase<T>::testMethod()':
GccTemplateCompile.cpp:12: error: expected primary-expression before
"int"
GccTemplateCompile.cpp:12: error: expected `;' before "int"
GccTemplateCompile.cpp:12: error: expected primary-expression before
"int"
GccTemplateCompile.cpp:12: error: expected `;' before "int"
Does anyone have any idea what's going on?
Thanks in advance,
Lawrence