1 Replies - 3313 Views - Last Post: 07 March 2012 - 02:33 PM

#1 JohnBoyMan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 24-February 12

c++ to cli enumeration

Posted 07 March 2012 - 01:53 AM

Hello all. I am working with managed c++ ,cli. I am working on a large project and cannot afford to make any mistakes. In cli from what i have seen usually when i construct classes i use this ^ character to do so, like this

//header file
public ref class something{};
 
//cpp file
something ^ s;




My problem is with enumerations because you make enumerations without the ref i used for the class something it looks like the fallowing.


    //header
    public: enum class C{
     
    //cpp
    C c;
     
    }




For anything else in managed c++ this would be unacceptable. Is there a ref enum class. If not will there be any problems associated with this. From what i can see this is mixing managed with un-managed, its usually not allowed, but at the moment the compiler lets it go. So whats the deal, and i good to go using it without the ref? thanks all for your eyes and time.

Is This A Good Question/Topic? 0
  • +

Replies To: c++ to cli enumeration

#2 ModMaker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 18
  • Joined: 12-July 10

Re: c++ to cli enumeration

Posted 07 March 2012 - 02:33 PM

First, ref designates that a class/struct is a reference type. Whether a type is ref class or ref struct results in the same managed code (don't quote me on this though). I think this is because of the background differences between a struct and class in C. To create a value type, you use value struct and value class.

Second, mixing managed and unmanaged code is fine, as long as you are careful and know what you are doing.

Third, the ^ is called a handle. It is the same as a pointer, just for managed types. You need the handle for any reference types. An enum is a value type and does not need a handle.

Fourth, you declared the enum correctly, assuming that you just copied the first line for the //header line. Also, you do not have the colon[:] after the word public unless the type is nested in a class.

This post has been edited by ModMaker: 07 March 2012 - 02:35 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1