This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

971031: template problem


Hello everybody.


The following code does not compile:

cat test.cc :

#include <set>

int main()
{
    set<set<int> > ss;
    set<int> s;

    ss.insert(s);
}


g++ test.cc :

Undefined                       first referenced
 symbol                             in file
operator<(set<int, less<int>, __default_alloc_template<false, 0> > const &, set<int, less<int>, __default_alloc_template<false, 0> > const &)/var/tmp/cca007Iv1.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status


In include/g++/set.h, line 152 the operator < is declared as a friend
of class set:

  friend bool operator<(const set&, const set&);

which is defined later (line 161) as:

template <class Key, class Compare, class Alloc>
inline bool operator<(const set<Key, Compare, Alloc>& x, 
                      const set<Key, Compare, Alloc>& y) {
  return x.t < y.t;
}



My first assumption was, that the friend declaration might be wrong
(maybe it's not?), thus I tried the following:


  friend bool operator<(const set<Key, Compare, Alloc>&, 
                        const set<Key, Compare, Alloc>&);

This didn't help either.
Making the operator an inline member function worked, though.



Best regards, Dirk Herrmann
----------------------------------------------------------------------
Beat the following spammer sites at their own game! SEND SPAM MAIL TO:
postmaster@agis.net postmaster@ascella.net



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]