This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
how can I solve this template problem?
- From: "변용덕" <ydbyun at lge dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 25 Apr 2003 08:57:09 +0900
- Subject: how can I solve this template problem?
- Reply-to: "변용덕" <ydbyun at lge dot com>
<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<<" constructor " << endl;
}
template
foo::~foo()
{
cout<<" destructor " << 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 <<" end of main"<<ENDL; PRE }<>