This is the mail archive of the gcc@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]

Re: c++ template class problem


On Wed, 23 Sep 1998, Toshinao ISHII wrote:

: g++ -c poi01.C -g -frepo
: g++ -o poi01 poi01.o

There are known but not admitted problems with -frepo on some platforms,
but:  you do have a bug in your code unrelated to this.

:     template <class T>
:     ostream& operator << ( ostream &os, const C<T>& c )
:     {
:       os << c;
:       return os;
:     }

This function is recursive.  It will call itself because you are doing `os
<< c' - which will call `operator << (ostream&, const C<T>&)' again, ad
infinitum.  This needs to cast `c' to something which has a different
operator <<, or somehow extract the proper data, probably with:

        os << c.v;

-- 
-- Todd Vierling (Personal tv@pobox.com; Bus. todd_vierling@xn.xerox.com)



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