473,564 Members | 2,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

managed enumerated type and ++ operator

I have an enumerated type like this:
public __value enum MyType{
ABC = 1,
DEF = 2,
GHI = 3,
JKL = 4
};

Later I have a for loop like this:
for (ft = MyType::ABC; ft <= MyType::JKL; ft++){

//Do stuff

}

I then get a compile error C2676: binary '++': 'MyType' does not define this
operator or a converstion to a type acceptable to the predefined operator.

So I tried to define the ++ operator.

MyType operator++(MyTy pe &ft, int){

return ft = (MyType)(ft+1);

}

That gives me compile error C3281: 'operator` ++": global operator cannot
have managed type 'MyType __gc &' in signature.

So my question: How do I get a managed enumerated type to allow me to use
the ++ operator to iterate through its values?

dwilson

Nov 17 '05 #1
2 1279
if you make that "ft" an "int" type, then it should work.

i guess you did

MyType ft;

you can do:

int ft;

// your for loop goes here

Nov 17 '05 #2
I have a solution, albeit a clunky one. I just change the for loop:

for (int i = MyType::ABC; i <= MyType::JKL; i++){
ft = (MyType) i;
//Do stuff
}

dwilson

"Daniel Wilson" <d.******@embtr ak.com> wrote in message
news:O1******** ******@TK2MSFTN GP12.phx.gbl...
I have an enumerated type like this:
public __value enum MyType{
ABC = 1,
DEF = 2,
GHI = 3,
JKL = 4
};

Later I have a for loop like this:
for (ft = MyType::ABC; ft <= MyType::JKL; ft++){

//Do stuff

}

I then get a compile error C2676: binary '++': 'MyType' does not define this operator or a converstion to a type acceptable to the predefined operator.

So I tried to define the ++ operator.

MyType operator++(MyTy pe &ft, int){

return ft = (MyType)(ft+1);

}

That gives me compile error C3281: 'operator` ++": global operator cannot
have managed type 'MyType __gc &' in signature.

So my question: How do I get a managed enumerated type to allow me to use
the ++ operator to iterate through its values?

dwilson

Nov 17 '05 #3

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

Similar topics

2
3344
by: Simon Storr | last post by:
Posting this again as it just got deleted off the server?! Is it possible to perform an 'in' set operator check on an enumerated type? For example something like enum WeekDays = {Mon,Tue,Wed,Thu,Fri,Sat,Sun}; WeekDays aWeekDay; .. .. ..
3
6184
by: Dave | last post by:
I'm at a point where I would really like to focus in on learning .NET but am having a hard time deciding which language to use. I learned to program in C++ but have spent quite a bit of time using VB6. I need to get started on developing a new application and would like to know what the advantages are of using managed C++ .NET over VB.NET or...
0
909
by: Marco Segurini | last post by:
Hi, I like to know why the compiler returns me an error if I implement operator<< for managed types as free function. //-------- #include <iostream> using namespace System;
1
1709
by: davidmcb | last post by:
I have defined an enumerated type that I use in various places in my schema. I am in the process of creating a new complex type that contains an attribute that I want to restrict to NOT being a member of the enumerated type. Is this possible? How? For example: <!-- enumerated type-->
4
4375
by: Shawnk | last post by:
This post is intended to verify that true value semantics DO NOT EXIST for the Enum class (relative to boolean operations). If this is true then (thus and therefore) you can not design state machines in C# where the machine can use the enumerated 'state' to execute (thus the term 'machine' as in 'state machine') the machine operations as...
7
2612
by: John Goche | last post by:
Hello, The following program compiler and runs fine under gcc and produces the output 3. However, I am not sure whether such behavior is legal. In particular, as a related question, how would I go about checking that a supplied integer is contained within the set of values of an enumeration? Is there a way to do this? Thanks,
5
2281
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason my C++.NET 2.0 textbook does not have one. I tried to build one using the format as taught in my regular C++ book, but I keep getting compiler...
1
1604
by: senfo | last post by:
I'm using an enumerated type to identify a record type that relates to a unique ID in a database. Identity columns in SQL start at 1, while enumerated types in C# start at 0. I didn't think it would be a big deal because I could just force the values of the enum to start at 1. Database: ID RecordType -- ---------- 1 TypeA
7
3037
by: Bill Davy | last post by:
I want to be able to write (const char*)v where v is an item of type Class::ToolTypeT where ToolTypeT is an enumeration and I've tried everything that looks sensible. There's an ugly solution, but surely this is possible? I could define an operator<< but for various reasons, I really want to convert to a 'const char*' (to embed into a...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.