home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.g++.help
- Path: sparky!uunet!mcsun!Germany.EU.net!news.netmbx.de!zrz.tu-berlin.de!math.fu-berlin.de!informatik.tu-muenchen.de!rz.uni-passau.de!kirk.fmi.uni-passau.de!funke
- From: funke@kirk.fmi.uni-passau.de (Christian Funke)
- Subject: templates and friends
- Message-ID: <1992Jul23.153433.16929@tom.rz.uni-passau.de>
- Sender: news@tom.rz.uni-passau.de (News-Operator)
- Nntp-Posting-Host: calvin.fmi.uni-passau.de
- Organization: University of Passau, Germany
- Date: Thu, 23 Jul 1992 15:34:33 GMT
- Lines: 61
-
- 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
-