From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: Overloading the << operator. Date: Sun, 03 Aug 1997 11:48:21 -0700 Organization: Alcyone Systems Lines: 31 Message-ID: <33E4D275.772779FD@alcyone.com> References: <33e40528 DOT 21082895 AT news DOT bright DOT net> NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Insomnia wrote: > > Is there any way to overload the << operator as a friend function in a > > class in djgpp? I tried the following: > > > > friend ostream &operator<<(ostream &, MyClass &); > > > > Unfortunately, djgpp didn't like this. Anyone have any ideas? > > > Try: > friend ostream &operator << (ostream &, const MyClass &); > ^^^^^ > This works fine for me. Overloaded operators, friend functions or member functions, certainly can take non-const references to objects as arguments. His problem is more fundamental than this. I suspect he's doing something like including the friend keyword when defining the friend function, rather than when declaring it. He'll have to post a short snippet of the example code, including the error and which line it's on, to get more help. -- Erik Max Francis, &tSftDotIotE / email / mailto:max AT alcyone DOT com Alcyone Systems / web / http://www.alcyone.com/max/ San Jose, California, United States / icbm / 37 20 07 N 121 53 38 W \ "Love is not love which alters / when it alteration finds." / William Shakespeare, _Sonnets_, 116