This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

how can I solve this template problem?


<BR>
<PRE>Hello,

I am Byun.

I have one question.

I use g++ 3.2.1 on linux system.

When I compiled my source program, g++ generate many link error. no compile error. only link error.

for example
i686-pc-linux_dbg.GNU3_2_1/main.o: In function `main':
/home/gcaman/test/template_test/main.cc:8: undefined reference to `foo::foo(in-charge)()'
/home/gcaman/test/template_test/main.cc:9: undefined reference to `foo::foo(in-charge)()'
/home/gcaman/test/template_test/main.cc:11: undefined reference to `foo::~foo (in-charge)()'
/home/gcaman/test/template_test/main.cc:11: undefined reference to `foo::~foo (in-charge)()'
/home/gcaman/test/template_test/main.cc:11: undefined reference to `foo::~foo (in-charge)()'
/home/gcaman/test/template_test/main.cc:11: undefined reference to `foo::~foo (in-charge)()'

if I added bellow code, has not link error. but original code has many template class. So How can I solve 
this problem to use g++ option.

#if 0
template class foo;
template class foo;
#endif




foo.cc
#include "foo.hh"

#include 


template
foo::foo()
{
 cout&lt;&lt;" constructor " &lt;&lt; endl;
}

template
foo::~foo()
{
 cout&lt;&lt;" destructor " &lt;&lt; endl ;
}



foo.hh

template 
class foo
{
 public:
   foo();
   ~foo();

 private:
   T data;
};


main.c
#include "foo.hh"
#include 
#include 


int main()
{
  foo<INT> a;
  foo<CHAR> b;

  cout &lt;&lt;" end of main"&lt;<ENDL; PRE }<>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]