Topic: Templates and sub/super-class... Help!!


Author: carlos@alto.unice.fr (Carlos Belmonte)
Date: 4 Dec 1994 16:12:36 GMT
Raw View


Help !!!!  I have two template classes such that

template<class T> class A
{
  ..............

friend A<T> operator==(const A<T>& a1,
                const A<T>& a2);

friend A<T> operator==(const T& value,
                       const A<T>& a);

  ..............

};


template<class T> class B : public A<T>
{
  ...............
}

gcc compiles it, but it does not link A<T>::operator==(...) if I do
not explicitly use it with arguments of class A; that is; if my
program is something like

#include <........>
#include "........"

int
main(void)
{
  B<int> b1;
  B<int> b2;

  if (b1==b2)
    cout << "equal!";
  else
    cout << "different!";
}


..then it complains saying

ld: Undefined symbol
   ___eq__FRCt6A1ZiT0
collect2: ld returned 2 exit status

But if I use A::operator==(..) with A class arguments it does not complain...
Help! what can I do? (yes, I know I can do it without templates, but
I *really* need them).

Drop me an e-mail please, any suggestion will be useful...
Thanks in advance..!

       Carlos.




=================================================================
Carlos Belmonte Calderon        e-mail: carlos@alto.unice.fr
Telcom Engineer.
I3S - CNRS URA 1376 - bat 4     Sophia-Antipolis
250 Avenue Albert Einstein      F 06560 Valbonne, France.
         __
         \  \     _ _          "He who wills, can.
          \**\ ___\/ \         He who tries, does.
        X*#####*+^^\_\         He who lives, loves."
          o/\  \
             \__\              "Els petits canvis son poderosos."
=================================================================