I develope a library, when I compile my code with GCC (in Windows with CodeBlocks), The source code doesn’t compile and this error appears:
error: incomplete type ‘claculator’ used in nested name specifier.
I write a sample code that generate this error exactly:
class claculator;
template<class T>
class my_class
{
public:
void test()
{
// GCC error: incomplete type 'claculator' used in nested name specifier
int x = claculator::add(1, 2);
}
T m_t;
};
// This class SHOULD after my_class.
// I can not move this class to top of my_class.
class claculator
{
public:
static int add(int a, int b)
{
return a+b;
}
};
int main()
{
my_class<int> c;
c.test();
return 0;
}
How can I solve this error?
Note that my source code compiled successfully in Visual Studio.
Thanks.
Its very simple. Define
test()after the definition ofcalculatorclass as:In this way, the complete definition of
calculatoris known to the compiler when it parses the definition oftest().