Hi! This is wholy mysterious to me. I'm using g++ on ubuntu, and this is some of my code (with class names change, but nothing else because I'm still using stubs everywhere):
Bob.hpp
template <class A>
class Bob : public Jack<Chris, A>
{
public:
Bob(int x1, int x2, float x3 = 1.0, float x4 = 2.0, float x5 = 3.0) throw(Exception);
virtual ~Bob();
};
I implemented in another file like this:
Bob.cpp
template <class A>
Bob<A>::Bob(int x1, int x2, float x3, float x4, float x5) throw(Exception)
{
}
template <class A>
Bob<A>::~Bob()
{
}
and I used it like this:
main.cpp
int main()
{
Bob<Alice> instance(1, 2);
}
Compiling with:
g++ -c Bob.cpp -o Bob.o
g++ -c main.cpp -o main.o
g++ -L"libs" -llib main.o Bob.o prog
gives me
main.o: In function main':
main.cpp:(.text+0x1fd): undefined reference to
Bob::Bob(int, int, float, float, float)'
collect2: ld returned 1 exit status
I am completely stumped. Changing the order with the g++ linking stage makes no difference. Compiling the object files generates no problems. And Why an undefined reference when I implemented the constructor? If anyone could shed any light on this, it's be much appreciated.