Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2005

Tip: Looking for answers? Try searching our database.

managed enumerated type and ++ operator

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel Wilson - 09 Mar 2005 16:09 GMT
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++(MyType &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
ismailp - 09 Mar 2005 19:37 GMT
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
Daniel Wilson - 09 Mar 2005 20:18 GMT
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

> I have an enumerated type like this:
> public __value enum MyType{
[quoted text clipped - 29 lines]
>
> dwilson

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.