Topic: friends and private struct
Author: "maxim" <maxk@touro.edu>
Date: 1999/12/08 Raw View
Sorry if you saw this om .lang.c++. It did not pick up there, but the q-n
has been bothering me for some time.
Can anyone justify the compiler's behavoir here?(using vc++6)
<Flc2199>
>>I heard there was a bug MS Visual C++ 6.0 compiler that did not >>allow
for friend functions to access private member varibles in >>classes. Is this
true?
<me>
I do not know about private vars,
but I had a problem with privately declared nested structs:
class Outer
{
struct Inner
{
};
public:
friend ostream& operator<<(ostream&, Inner&);
};
ostream& operator<<(ostream& out, Outer::Inner&)
{
return out;
}
gets
error C2248: 'Inner' : cannot access private struct declared in class
'Outer'
D:\users\max\sandbox\ciffile\main.cpp(41) : see declaration of
'Inner'
from VC++6.
So does
class Outer
{
struct Inner
{
friend ostream& operator<<(ostream&, Inner&);
};
public:
};
ostream& operator<<(ostream& out, Outer::Inner&)
{
return out;
}
And finally
class Outer
{
struct Inner
{
};
public:
friend ostream& operator<<(ostream&, Outer::Inner&);
};
ostream& operator<<(ostream& out, Outer::Inner&)
{
return out;
}
Go figure!
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]