delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/06/15:21:01

From: Erik Max Francis <max AT alcyone DOT com>
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> <Pine DOT SUN DOT 3 DOT 93 DOT 970803122401 DOT 8956A-100000 AT degobah>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019