🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1831

Scoping and friends

#1831
From: Scott Maxwell
Date: Wed, 23 Aug 1995 21:54
52 lines
1872 bytes
When a friend function of a private (or protected) nested class tries
to use the type name of the class it's a friend of, I get errors under
Borland C++ 4.5 but not under g++ 2.6.3.  Who's right?

I'd really rather use friends than static mfns, since the functions in
the real code I'm writing are being used as callbacks in a window system.

As a fer-instance:

class Outer
{
    class Inner
    {
        int x;

    public:
        Inner(void): x(0)  {}
        friend void pal(Inner &);  // Friend fn that modifies an Inner.
        static void smf(Inner &);  // Static mfn that does the same thing.
    } i1, i2;

public:
    Outer(void) {}
    void blah(void)
    {
        smf(i1);  smf(i2);
        pal(i1);  pal(i2);
    }
};

void Outer::Inner::smf(Outer::Inner & i)  // No problem.
{
    i.x++;
}

void pal(Outer::Inner & i)  // BC++ error: "Outer::Inner is not accessible"!
{
    i.x++;
}


int main(void)
{
    Outer outer;
    outer.blah();
    return 0;
}

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <MAXWELL.95Aug23144855@oeltemp1.jpl.nasa.gov>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: maxwell@oeltemp1.jpl.nasa.gov (Scott Maxwell)
Newsgroups: comp.std.c++
Subject: Scoping and friends
Date: 23 Aug 1995 21:54:41 GMT
Organization: Jet Propulsion Laboratory - Pasadena CA
Approved: clamage@eng.sun.com (comp.std.c++)
Distribution: world
Message-ID: <MAXWELL.95Aug23144855@oeltemp1.jpl.nasa.gov>
NNTP-Posting-Host: taumet.eng.sun.com
Mime-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"; conversions="7bit"
Content-Transfer-Encoding: 7bit
X-Nntp-Posting-Host: oeltemp1.jpl.nasa.gov
X-Lines: 48
Content-Length: 972
Originator: clamage@taumet