Discussion:
C2248: cannot access protected member
(too old to reply)
Alex Blekhman
2010-03-15 10:37:30 UTC
Permalink
Hello,

Some time ago I asked a question about taking an address of protected
member function:

"C2248: cannot access protected member"
http://groups.google.com/group/microsoft.public.vc.language/browse_frm/thread/a6b6afdca3ea91a2/

Recently I discovered that proposed solution fails to compile with
VC++2008 if the classes are nested and member function is referenced via
fully qualified name:

class Outer
{
class X;
class Y;
};

class Outer::X
{
protected:
void foo() {}
int a;
};

class Outer::Y : public Outer::X
{
public:
void bar()
{
void (Outer::Y::*pf)() = &Outer::Y::foo; // C2248
int Outer::Y::*pa = &Outer::Y::a; // C2248
}
};

If I omit the `Outer' part, then everything compiles smoothly:

void (Outer::Y::*pf)() = &Y::foo;
int Outer::Y::*pa = &Y::a;

Comeau C++ online test compiles the code either way, so I believe it's a
bug in VC++ 2008.

Before I open a bug report, do I miss something here?

Thanks
Alex
Victor Bazarov
2010-03-15 13:31:52 UTC
Permalink
Post by Alex Blekhman
Some time ago I asked a question about taking an address of protected
[...]
Comeau C++ online test compiles the code either way, so I believe it's a
bug in VC++ 2008.
Before I open a bug report, do I miss something here?
The fact that 2010 is almost out the door? Just a thought. Might want
to verify the behaviour and file the bug against that too (or not).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Alex Blekhman
2010-03-15 17:20:07 UTC
Permalink
Post by Victor Bazarov
The fact that 2010 is almost out the door? Just a thought.
Might want to verify the behaviour and file the bug against that
too (or not).
Good idea. Currently I don't have VS 2010 at hand to check it out.
Could anybody of the readers of this group check the code with
VC++ 2010?

Alex
Victor Bazarov
2010-03-15 19:30:06 UTC
Permalink
The fact that 2010 is almost out the door? Just a thought. Might want
to verify the behaviour and file the bug against that too (or not).
Good idea. Currently I don't have VS 2010 at hand to check it out. Could
anybody of the readers of this group check the code with VC++ 2010?
I'll do it at home tonight if I remember to.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
John H.
2010-03-15 21:36:25 UTC
Permalink
Post by Alex Blekhman
Could anybody of the readers of this group check the code with
VC++ 2010?
I get the same errors in VC++ 2010 RC.
g++ 3.4.4 and 4.3.4 both accept it without error.

Loading...