473,382 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Unusual scope question

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 } };
}
};

Apr 26 '07 #1
3 1315
earthwormgaz wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 26 '07 #2
On 04/26/2007 09:08 AM, earthwormgaz wrote:
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.

Apr 26 '07 #3
On Apr 26, 10:08 am, earthwormgaz <earthworm...@googlemail.comwrote:
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 } };
}

};


Apr 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: Arthur | last post by:
>>>a= >>> for p in a: print p 1 2 3 >>> p 3 My naive expectation was that p would be 'not defined' from outside
6
by: Razvan | last post by:
Hi, I took a C++ test and I found the following question: Q. Inside a class member function definition, which scope is searched
18
by: Minti | last post by:
I was reading some text and I came across the following snippet switch('5') { int x = 123; case '5': printf("The value of x %d\n", x); break; }
4
by: Gery D. Dorazio | last post by:
Gurus, If a static variable is defined in a class what is the scope of the variable resolved to for it to remain 'static'? For instance, lets say I create a class library assembly that is...
0
by: Bruno van Dooren | last post by:
Hi, i have a somewhat unusual question that is not really a c++ question, but maybe one of you can help me. I have programmed a windows service application that runs on an embedded pc. the...
165
by: Dieter | last post by:
Hi. In the snippet of code below, I'm trying to understand why when the struct dirent ** namelist is declared with "file" scope, I don't have a problem freeing the allocated memory. But...
6
by: Frank Silvermann | last post by:
I have taken an extraordinary leap into the modern world by purchasing webspace. In addition to my private concerns, I would like to make a part to which others, e.g. my nieces and ex-wife, can...
7
by: Christian Christmann | last post by:
Hi, I've a a question on the specifier extern. Code example: void func( void ) { extern int e; //...
5
by: somenath | last post by:
Hi All , I have one question regarding scope and lifetime of variable. #include <stdio.h> int main(int argc, char *argv) { int *intp = NULL; char *sptr = NULL;
10
by: Tomás Ó hÉilidhe | last post by:
I've been writing mostly C code for the last year or so (rather than C++), and in writing C code I always make it fully portable, allowing for 9-Bit bytes, allowing for padding within integer...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.