how can I solve this problem?
변용덕
ydbyun@lge.com
Thu Apr 24 09:33:00 GMT 2003
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;
}
More information about the Gcc
mailing list