public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Undefined reference to static member in templated class
@ 2001-07-18  9:43 Arun Saini
  2001-07-18 12:25 ` David Edelsohn
  0 siblings, 1 reply; 2+ messages in thread
From: Arun Saini @ 2001-07-18  9:43 UTC (permalink / raw)
  To: gcc

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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Undefined reference to static member in templated class
  2001-07-18  9:43 Undefined reference to static member in templated class Arun Saini
@ 2001-07-18 12:25 ` David Edelsohn
  0 siblings, 0 replies; 2+ messages in thread
From: David Edelsohn @ 2001-07-18 12:25 UTC (permalink / raw)
  To: Arun Saini; +Cc: gcc

>>>>> Arun Saini writes:

Arun> I am using gcc-2.95.3 on AIX 4.3.3 / RS/6000. I am enclosing here a small
Arun> piece of code that compiled and executed correctly on gcc-3.0 on a Linux
Arun> system. It however fails on the AIX system.

	GCC has known problems with templates on AIX because GCC does not
have a very advanced template generation facility and relies on WEAK
symbols to clean up after it.  AIX does not provide WEAK symbols.

	For AIX, one needs to use -fno-implicit-templates option for GCC
and explicitly instantiate the necessary templates in the code.

David

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-07-18 12:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-18  9:43 Undefined reference to static member in templated class Arun Saini
2001-07-18 12:25 ` David Edelsohn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).