M
mati
Hi,
Following code gives a linker error:
test.obj : error LNK2001: unresolved external symbol "public: static int
const BresenhamCircle<2>::SIZE"
template <int R>
class BresenhamCircle
{
public:
static const int SIZE;
};
template <int R>
class Test
{
BresenhamCircle<R> circle;
public:
int testfunction();//[1] { return circle.SIZE+1000*R; }
};
template<int R>
int Test<R>::testfunction()
{
return circle.SIZE+1000*R;
}
template<int R> const int BresenhamCircle<R>::SIZE = -1;
const int BresenhamCircle<4>::SIZE = 4;
#include <iostream>
int main()
{
Test<2> obj;
//[2] Test<4> obj;
std::cout<<obj.testfunction()<<std::endl;
}
And two interesting things happen:
[1] - code compiles and links without errors when we make the
testfunction() inline.
[2] - all is ok for specialized versions;
I'm learning c++, and I have no idea if I'm wrong, or the compiler has a
bug, but I suppose the latter since gcc(3.3.6) compiles this code just
fine (or maybe it is UB?). I do not understand why the behaviour is
different for inline and non-inline functions.
I'm using
Microsoft Visual Studio 2005 (VC Express)
Version 8.0.50727.42 (RTM.050727-4200)
Following code gives a linker error:
test.obj : error LNK2001: unresolved external symbol "public: static int
const BresenhamCircle<2>::SIZE"
template <int R>
class BresenhamCircle
{
public:
static const int SIZE;
};
template <int R>
class Test
{
BresenhamCircle<R> circle;
public:
int testfunction();//[1] { return circle.SIZE+1000*R; }
};
template<int R>
int Test<R>::testfunction()
{
return circle.SIZE+1000*R;
}
template<int R> const int BresenhamCircle<R>::SIZE = -1;
const int BresenhamCircle<4>::SIZE = 4;
#include <iostream>
int main()
{
Test<2> obj;
//[2] Test<4> obj;
std::cout<<obj.testfunction()<<std::endl;
}
And two interesting things happen:
[1] - code compiles and links without errors when we make the
testfunction() inline.
[2] - all is ok for specialized versions;
I'm learning c++, and I have no idea if I'm wrong, or the compiler has a
bug, but I suppose the latter since gcc(3.3.6) compiles this code just
fine (or maybe it is UB?). I do not understand why the behaviour is
different for inline and non-inline functions.
I'm using
Microsoft Visual Studio 2005 (VC Express)
Version 8.0.50727.42 (RTM.050727-4200)