🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Christian Funke Thu, 23 Jul 1992 15:34
templates and friends
#88
Author: Christian Funke
Date: Thu, 23 Jul 1992 15:34
61 lines
1958 bytes
Hi there!

I have read  there are problems with gcc-2.1 and template classes, which
define non-inline element functions. Does anyone know, if there are problems
generating friend functions for template classes?
How can I correctly build something like that:

#include <iostream.h>

template <class A, class B>
class hubo {
   A avar;
   B bvar;
  public:
   hubo(void):avar(0),bvar(0) {}
   hubo(A a, B b):avar(a), bvar(b) {}
   friend ostream& operator<<(ostream& o, hubo& h);
   
   friend istream& operator>>(istream& i, hubo& h)
     {
       return i >> h.avar >> h.bvar ;
       
     }
};


ostream& operator<<(ostream& o,  hubo< WHAT_COMES, HERE? >& h)
{
  return o << "Hubo[" << h.avar << ',' << h.bvar << "]\n";
}

main()
{
  hubo<double,int> C;
  
  cout << C << '\n';
  
}



When inserting this piece of code [

ostream& operator<<(ostream& o, hubo<double,int>& h)
{
  return o << "Hubo[" << h.avar << ',' << h.bvar << "]\n";
}
 
] instead of something else, gcc-2.1 complains about a missing type conversion
for the ostream& operator<< :

TTest.cc: In function `int  main ()':
TTest.cc:40: type conversion required for type `hubo<double ,int>'

...and what makes things even more strange: when looking at the assembly output
gcc does generate the correct name for operator<< (its the same when defining it
inside the class declaration)

What's wrong?

Chris
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads