c++ - undefined reference with member implelementation of a templated class -


This is mysterious for me. I am using G ++ on Ubuntu, and this is my code (class With names change, but nothing is because I'm still using stubs everywhere):

Bob.hpp

  template & Lt; Class A & gt; Class Bob: Public Jack & lt; Chris, A & gt; {Public: Bob (int x1, int x 2, float x3 = 1.0, float x4 = 2.0, float x5 = 3.0) throw (exception); Virtual ~ bob (); };  

I have implemented this in another file like this:

Bob.cpp

  template & Lt; Class one & gt; Bob & lt; A & gt; :: Bob (int x1, int x2, float x3, float x4, float x5) throw (exception) {} template & lt; Class A & gt; Bob & lt; A & gt; :: ~ Bob () {}  

And I used it like this:

main.cpp

  int main () {bob & lt; Alice & gt; Example (1, 2); }  

Compile with:

  G ++ - A Bob CPP - O Bob.OG ++ - C Micrapee - O.O.O.O.G + + L "Libs" -lib main.o Bob.o prog  

gives me main.o: in the function main ': main.cpp :(. Text + 0x1fd): Undefined Reference

I'm completely stumped. Changing the order with the G ++ linking phase is no different. Compiling object files does not cause any problems. And why is an undefined reference when I implemented the constructor? If someone can put any light on it, then it can be appreciated.

You need to move the code from Bob.cpp in Bob.cpp when compiler bob :: Bob: Bob: "Bob": Bob sees the definitions of Bob.cpp in Bob, then it does not know what type of institute Bob is going to be (i.e. Bob The & lt; int & gt; vs Bob & lt; SomeClass & gt; and the code is not ready for that. Alternatively, you still have the code in the Bob.cpp file You can keep it, but you have to declare it What types of bob are you going to be, such as: inside Bob CPP:

  template class Bob & lt; Alice>;  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -