This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Undefined reference to static member in templated class
- To: gcc at gcc dot gnu dot org
- Subject: Undefined reference to static member in templated class
- From: Arun Saini <arunsaini at yahoo dot com>
- Date: Wed, 18 Jul 2001 09:42:54 -0700 (PDT)
hi all,
I am using gcc-2.95.3 on AIX 4.3.3 / RS/6000. I am enclosing here a small
piece of code that compiled and executed correctly on gcc-3.0 on a Linux
system. It however fails on the AIX system.
#include<cstdio>
enum eTables
{
tbl1,
tbl2
};
template <class a, eTables e> class test
{
private:
static test<a, e> * foo;
protected:
public:
test();
virtual ~test();
static test<a, e> *Instance();
}; //class test
template <class a, eTables e>
test<a, e>
*test<a, e>::foo = NULL;
template <class a, eTables e>
test<a, e>::test()
{
}
template <class a, eTables e>
test<a, e>::~test()
{
}
template <class a, eTables e>
test<a,e>
*test<a, e>::Instance()
{
if (foo == NULL)
{
foo = new test<a, e>;
}
return(foo);
}
int main()
{
test<int, tbl1> *pobj;
pobj = test<int, tbl1>::Instance();
}
# g++ testFinal.cpp
/tmp/cc8zh32c.o(.pr+0x13e):testFinal.cpp: undefined reference to `test<int,0>::foo'
/tmp/cc8zh32c.o(.pr+0x14e):testFinal.cpp: undefined reference to `test<int,0>::foo'
/tmp/cc8zh32c.o(.pr+0x21a):testFinal.cpp: undefined reference to `test<int,0>::foo'
/tmp/cc8zh32c.o(.tc+0x0):testFinal.cpp: undefined reference to `test<int,0>::foo'
collect2: ld returned 1 exit status
Any ideas why this might be happening????
Arun Saini
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/