[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Undefined reference to '...'



I took your program example and compiled it, and it works... but here comes the
groovy part.  If you take the same program and split it...

|---begin temp.C----|

#include "temp.h"

template<class T>
ancestor<T>::ancestor(T x)
{
  cout << "ancestor()" << endl;
  myvar = x;
}

template<class T>
ancestor<T>::~ancestor()
{
  cout << "~ancestor()" << endl;
}

template<class T>
ancestor<T>::dump()
{
  cout << "ancestor.myvar = " << myvar << endl;
}

|--- end temp.C ---|

|--- begin tempMain.C ---|

#include "temp.h"

int
main( int argc, char* argv ) {
   ancestor<int> something(5);

   something.dump();

   return 0;
}

|--- end tempMain.C ---|

|--- begin temp.h ---|

#include <iostream.h>

template<class T>
class ancestor {
private:
   T myvar;
public:
   ancestor(T x);
   ~ancestor();
   void dump();
};


|--- end temp.h ---|

and compile it...

>g++ -c temp.C -o temp.o
>g++ -c tempMain.C -o tempMain.o
>g++ tempMain.o temp.o -o Temp
tempMain.o: In function `main':
tempMain.o(.text+0xe): undefined reference to `ancestor<int>::ancestor(int)'
tempMain.o(.text+0x1a): undefined reference to `ancestor<int>::dump(void)'
tempMain.o(.text+0x2a): undefined reference to `ancestor<int>::~ancestor(void)'


...and that's weird.


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: