🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Scott Maxwell Wed, 23 Aug 1995 21:54
Scoping and friends
#1831
Author: 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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads