473,394 Members | 1,726 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,394 software developers and data experts.

enum handling change in VS 2005

All,

I've installed the VS 2005 Beta 1 and was trying to build our current
product. I get a compile error when enum value is specified with
classname::enumname::enumvalue. Seems the compiler does not want the
enumname there anymore. This was not a problem with any previous versions of
VS. I could not find any help in any of my programming books or in MSDN. Can
anyone explain the reasons to me? Is this behavior to stay?

class CMyEnumClass

{

public:

enum MyMode

{

MM_Mode1,

MM_Mode2,

MM_Mode3,

MM_Mode4

};

};

int _tmain(int argc, _TCHAR* argv[])

{

// CMyEnumClass::MyMode m = CMyEnumClass::MyMode::MM_Mode3;// in VS 2005 -
error C2825: 'CMyEnumClass::MyMode': must be a class or namespace when
followed by '::'

CMyEnumClass::MyMode m2 = CMyEnumClass::MM_Mode3;//ok in ALL

return 0;

}

Thanks!

Craig Klementowski
Nov 17 '05 #1
8 2211
Actually, I never knew you could include the enum's name in the reference to
the enum, but it seems to be ok for vs2003. However, in my opinion, allowing
this would make the following case legal also, since you can differ which
"something" you want, like s::e1::something or s::e2::something.

struct s
{
enum e1 {something = 1};
enum e2 {something = 2};
};
Nov 17 '05 #2
The fact that the VC 7.1 compiler allowed this was a bug that we fixed for
the 2005 version. Enums are not scope qualified according to both the C and
C++ standards.

Ronald Laeremans
Visual C++ team

"Craig Klementowski" <no**************@nospam.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
All,

I've installed the VS 2005 Beta 1 and was trying to build our current
product. I get a compile error when enum value is specified with
classname::enumname::enumvalue. Seems the compiler does not want the
enumname there anymore. This was not a problem with any previous versions
of
VS. I could not find any help in any of my programming books or in MSDN.
Can
anyone explain the reasons to me? Is this behavior to stay?

class CMyEnumClass

{

public:

enum MyMode

{

MM_Mode1,

MM_Mode2,

MM_Mode3,

MM_Mode4

};

};

int _tmain(int argc, _TCHAR* argv[])

{

// CMyEnumClass::MyMode m = CMyEnumClass::MyMode::MM_Mode3;// in VS 2005 -
error C2825: 'CMyEnumClass::MyMode': must be a class or namespace when
followed by '::'

CMyEnumClass::MyMode m2 = CMyEnumClass::MM_Mode3;//ok in ALL

return 0;

}

Thanks!

Craig Klementowski

Nov 17 '05 #3
Thanks Ron. I'll get to cleaning up our code then.

Craig

"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in message
news:e6**************@TK2MSFTNGP11.phx.gbl...
The fact that the VC 7.1 compiler allowed this was a bug that we fixed for
the 2005 version. Enums are not scope qualified according to both the C and C++ standards.

Ronald Laeremans
Visual C++ team

"Craig Klementowski" <no**************@nospam.hotmail.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
All,

I've installed the VS 2005 Beta 1 and was trying to build our current
product. I get a compile error when enum value is specified with
classname::enumname::enumvalue. Seems the compiler does not want the
enumname there anymore. This was not a problem with any previous versions of
VS. I could not find any help in any of my programming books or in MSDN.
Can
anyone explain the reasons to me? Is this behavior to stay?

class CMyEnumClass

{

public:

enum MyMode

{

MM_Mode1,

MM_Mode2,

MM_Mode3,

MM_Mode4

};

};

int _tmain(int argc, _TCHAR* argv[])

{

// CMyEnumClass::MyMode m = CMyEnumClass::MyMode::MM_Mode3;// in VS 2005 - error C2825: 'CMyEnumClass::MyMode': must be a class or namespace when
followed by '::'

CMyEnumClass::MyMode m2 = CMyEnumClass::MM_Mode3;//ok in ALL

return 0;

}

Thanks!

Craig Klementowski


Nov 17 '05 #4
"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in message news:<e6**************@TK2MSFTNGP11.phx.gbl>...
The fact that the VC 7.1 compiler allowed this was a bug that we fixed for
the 2005 version. Enums are not scope qualified according to both the C and
C++ standards.

Ronald Laeremans
Visual C++ team


Ron,

Given all the extensive language extensions provided as part of .NET,
I think it would be a very good idea to leave the enum scope
qualification as a language extension.

Not only does it make MC++ more similar to C#.NET, but it's simply a
good idea on its own regard. Lack of enum scoping frequently forces
name mutilation into the enum fields:

enum EColor
{
eColor_Red,
eColor_Blue,
}

This sucks in any case where you want to use the textual value of the
enum for printout purposes.

Finally, doesn't removing enum scope qualification in MC++ introduce
possibilities where MC++ will be unable to interact with enums defined
in C#.NET? Since C# supports enum scoping, it seems there could be
cases where duplicate enumerared values (potentially with different
meaning or numeric values) are defined in different enum types. C# can
handle this fine, but MC++ cannot?

Thanks,
-ken
Nov 17 '05 #5
Hi Ken,

enum class Foo {... } will act identical to an enum defined in C# or another
CLR language.
enum Foo { ... } will act as per the ANSI/ISO C and C++ standards.

If you want a non managed enum to behave the same it is fairly easy to write
a class in standard C++ that has the scoped behavior and use that instead.

Ronald

"Ken Durden" <cr*************@hotmail.com> wrote in message
news:18**************************@posting.google.c om...
"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in message
news:<e6**************@TK2MSFTNGP11.phx.gbl>...
The fact that the VC 7.1 compiler allowed this was a bug that we fixed
for
the 2005 version. Enums are not scope qualified according to both the C
and
C++ standards.

Ronald Laeremans
Visual C++ team


Ron,

Given all the extensive language extensions provided as part of .NET,
I think it would be a very good idea to leave the enum scope
qualification as a language extension.

Not only does it make MC++ more similar to C#.NET, but it's simply a
good idea on its own regard. Lack of enum scoping frequently forces
name mutilation into the enum fields:

enum EColor
{
eColor_Red,
eColor_Blue,
}

This sucks in any case where you want to use the textual value of the
enum for printout purposes.

Finally, doesn't removing enum scope qualification in MC++ introduce
possibilities where MC++ will be unable to interact with enums defined
in C#.NET? Since C# supports enum scoping, it seems there could be
cases where duplicate enumerared values (potentially with different
meaning or numeric values) are defined in different enum types. C# can
handle this fine, but MC++ cannot?

Thanks,
-ken

Nov 17 '05 #6
Yamake Takahashi wrote:
If that's the case, people might as well use:

typedef unsigned int [enum_name];
const unsigned int [enum_values_0] = 0;
const unsigned int [enum_values_1] = 1;
// ... and so on ...
That is what people do today to workaround the C++ limitations for enums.
This new enum stuff confuses me.


You're not alone. Effectively, everyone is observing how enums are really
broken in C++. They are the way they are for compatibility with C. As with
most broken features in C++, compatibility with C is the culprit.

Interoperating with nearly every other language that has a better approach
to enums required us to introduce another kind of enum.

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
Nov 17 '05 #7
I have a DLL which exposes a class which has a function which returns
a enum defined inside the class. Does this mean that I will have to
pull the enum definition outside the class??

i.e.
------------(.H file)
class Temp
{
public:
enum RetCode
{
SUCCESS,
FAILURE
};

static RetCode CreateClass();
}
extern "C" Temp_API Temp::RetCode Temp_CreateClass();
------------(.CPP file)
extern "C" Temp_API Tesmp::RetCode Temp_CreateClass()
{
return Temp::RetCode::SUCCESS;
}

Now in VS2005 I get the error and if I remove the Temp::RetCode the
compiler does not recognize SUCCESS. No scope.

Thanks
Jeff
Nov 17 '05 #8

"Jeffrey B. Holtz" <jh****@accuratetechnologies.com> skrev i meddelandet
news:93**************************@posting.google.c om...
I have a DLL which exposes a class which has a function which returns
a enum defined inside the class. Does this mean that I will have to
pull the enum definition outside the class??

i.e.
------------(.H file)
class Temp
{
public:
enum RetCode
{
SUCCESS,
FAILURE
};

static RetCode CreateClass();
}
extern "C" Temp_API Temp::RetCode Temp_CreateClass();
------------(.CPP file)
extern "C" Temp_API Tesmp::RetCode Temp_CreateClass()
{
return Temp::RetCode::SUCCESS;
}

Now in VS2005 I get the error and if I remove the Temp::RetCode the
compiler does not recognize SUCCESS. No scope.
It should be just Temp::SUCCESS.

The RetCode isn't a part of the scope, but VC 6 & 7 didn't realize this.
This is a bug that has been fixed!

Bo Persson


Thanks
Jeff

Nov 17 '05 #9

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

Similar topics

6
by: PengYu.UT | last post by:
Hi, I have some problem when I use enum with stream. The code segment is listed below. I know if I change the first line to "int op;", there will not be any error. However, what I really want is...
18
by: Nebula | last post by:
Consider enum Side {Back,Front,Top,Bottom}; enum Side a; Now, why is a = 124; legal (well it really is an integer, but still, checking could be performed..) ? Wouldn't enums be more useful if...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
18
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an enum list like this: enum myEnum : int { This = 2, That, NewVal = 10, LastItm
6
by: | last post by:
I'm new to VS.NET, C#, and the enumerated datatype. I'm told that VS.NET 2005 Intellisense will pop up the members of an enum as a selection list if you are using the enum as a method parameter....
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
4
by: jonpb | last post by:
The documentation for the "is" keyword says: An is expression evaluates to true if the provided expression is non-null, and the provided object can be cast to the provided type without causing...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.