delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/24/13:55:13

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Class Question
Date: Wed, 23 Dec 1998 13:45:12 -0800
Organization: Alcyone Systems
Lines: 30
Message-ID: <36816468.38CAE503@alcyone.com>
References: <3680B11B DOT 6E9A3486 AT earthlink DOT net>
NNTP-Posting-Host: charmaine.alcyone.com
Mime-Version: 1.0
X-Mailer: Mozilla 4.5 [en] (X11; I; Linux 2.0.34 i686)
X-Accept-Language: en, eo
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Steven S. Falls" wrote:
> 
>    Is their a way to make a global function acsess the private members
> of a class directly? In other words can you make global functions
> friends of classes?

Sure, it's routinely done with iostream inserters and extractors, for
instance (since the first argument to them must be an iostream
reference:

    class Vector
    {
        ...

        friend ostream &operator <<(ostream &os, const Vector &v);
        friend istream &operator >>(istream &is, Vector &v);
    };

    ostream &operator <<(ostream &os, const Vector &v) { ... }

    istream &operator >>(istream &is, Vector &v); { ... }

-- 
Erik Max Francis / email max AT alcyone DOT com / whois mf303 / icq 16063900
Alcyone Systems / irc maxxon (efnet) / finger max AT finger DOT alcyone DOT com
  San Jose, CA / languages En, Eo / web http://www.alcyone.com/max/
          USA / icbm 37 20 07 N 121 53 38 W / &tSftDotIotE
             \
            / Love is the wisdom of the fool and the folly of the wise.
           / Samuel Johnson

- Raw text -


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