Unusual scope question

E

earthwormgaz

The Metrowerks compiler does not think that a local struct declared
within a method of a class should be able to see private data of that
class. Is this a feature of the standard or a quirk of this compiler
does anyone know?

Example ...

class A
{
private:
enum MyEnum
{
A,
B
};

void MyMethod()
{
struct
{
MyEnum val
} values[] =
{ { A }, { B } };
}
};
 
V

Victor Bazarov

earthwormgaz said:
The Metrowerks compiler does not think that a local struct declared
within a method of a class should be able to see private data of that
class. Is this a feature of the standard or a quirk of this compiler
does anyone know?

Example ...

class A
{
private:
enum MyEnum
{
A,
B
};

void MyMethod()
{
struct
{
MyEnum val
} values[] =
{ { A }, { B } };
}
};

A local struct is not a member of the class, hence it doesn't have
access to private elements of the class.

V
 
M

Mumia W.

The Metrowerks compiler does not think that a local struct declared
within a method of a class should be able to see private data of that
class. Is this a feature of the standard or a quirk of this compiler
does anyone know?

Example ...

class A
{
private:
enum MyEnum
{
A,
B
};

void MyMethod()
{
struct
{
MyEnum val
} values[] =
{ { A }, { B } };
}
};

GCC 3.3.5 says this for the line that reads "class A":
error: duplicate field `class A' (as enum and non-enum)

IOW, you have a name collision between A the class and A the enum value.
 
S

Salt_Peter

The Metrowerks compiler does not think that a local struct declared
within a method of a class should be able to see private data of that
class. Is this a feature of the standard or a quirk of this compiler
does anyone know?

Example ...

class A

class TypeA
{
private:
enum MyEnum
{
A,
B
};

void MyMethod()
{
struct
{
MyEnum val

MyEnum val; // semicolon
} values[] =
{ { A }, { B } };
}

};
 

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,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top