Topic: Scoping and friends
Author: maxwell@oeltemp1.jpl.nasa.gov (Scott Maxwell)
Date: 1995/08/23 Raw View
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. ]