P
pembed2003
hi all,
i have a template class that looks like:
******
foo.h:
******
#ifndef _FOO_H_
#define _FOO_H_
template<class T>
class Foo{
public:
...
privdate:
...
};
#endif
*********
foo.cpp:
*********
#include "foo.h"
template<class T>
Foo<T>::Foo(){
...
}
template<class T>
Foo<T>::~Foo(){
...
}
i compiled that into a foo.o with:
g++ -c foo.cpp
and then i have a driver:
#include "foo.h"
int main(int argc,char** argv){
Foo<int> f;
}
and i compile the driver with:
g++ driver.cpp foo.o -o driver
but there is error:
/tmp/c8KKKLKD.o(.text+0x19): In function `main':
:undefined reference to `Foo<int>::Foo[in-charge]()'
.... etc
if i send the same problem to a VC++ compiler, it compiles ok. why is
g++ not able to compile the program? why can't it find the
constructor, i already supply foo.o so it should find the function
there.
any help? thanks!
i have a template class that looks like:
******
foo.h:
******
#ifndef _FOO_H_
#define _FOO_H_
template<class T>
class Foo{
public:
...
privdate:
...
};
#endif
*********
foo.cpp:
*********
#include "foo.h"
template<class T>
Foo<T>::Foo(){
...
}
template<class T>
Foo<T>::~Foo(){
...
}
i compiled that into a foo.o with:
g++ -c foo.cpp
and then i have a driver:
#include "foo.h"
int main(int argc,char** argv){
Foo<int> f;
}
and i compile the driver with:
g++ driver.cpp foo.o -o driver
but there is error:
/tmp/c8KKKLKD.o(.text+0x19): In function `main':
:undefined reference to `Foo<int>::Foo[in-charge]()'
.... etc
if i send the same problem to a VC++ compiler, it compiles ok. why is
g++ not able to compile the program? why can't it find the
constructor, i already supply foo.o so it should find the function
there.
any help? thanks!