Nested class member pointer access

M

Magnus Hiie

Hello,

I compiled some source with the new Visual Studio 2005 C++ compiler and
got some unexpected error. Most other compilers (incl. VC6, gcc) are
fine with the code.

Extracted sample:
class FriendClass
{
class MemberClass
{
private:
int member;
static int staticMember;
friend class FriendClass;
};

public:
FriendClass(void);
};

FriendClass::FriendClass(void)
{
int FriendClass::MemberClass::* ptr =
&FriendClass::MemberClass::member; // C2326
int *i = &FriendClass::MemberClass::staticMember; // OK
int FriendClass::MemberClass::* ptr2 = &MemberClass::member; // OK
int *i2 = &MemberClass::staticMember; // OK
}

Is this code legal in C++ or is the VC2005 compiler right?

Best regards,
Magnus
 
I

Ivan Vecerina

: Hello,
:
: I compiled some source with the new Visual Studio 2005 C++ compiler and
: got some unexpected error. Most other compilers (incl. VC6, gcc) are
: fine with the code.
BTW Comeau (http://www.comeaucomputing.com/tryitout/) also
finds the code to be ok.

: Extracted sample:
: class FriendClass
: {
: class MemberClass
: {
: private:
: int member;
: static int staticMember;
: friend class FriendClass;
: };
:
: public:
: FriendClass(void);
: };
:
: FriendClass::FriendClass(void)
: {
: int FriendClass::MemberClass::* ptr =
: &FriendClass::MemberClass::member; // C2326
NB: which is:
'FriendClass::FriendClass(void)' : function cannot access
FriendClass::MemberClass::member'

: int *i = &FriendClass::MemberClass::staticMember; // OK
: int FriendClass::MemberClass::* ptr2 = &MemberClass::member; // OK
: int *i2 = &MemberClass::staticMember; // OK
: }
:
: Is this code legal in C++ or is the VC2005 compiler right?

This seems to be a compiler bug in VS2005.
Worth submitting to the vendor IMHO...

Ivan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,222
Latest member
patricajohnson51

Latest Threads

Top