none
No Implicit cast between C++ and C# for managed enums? RRS feed

  • Question

  • I find this behavior strange.  I have defined a managed enum and a class that uses it in a C++ managed wrapper as follows:

    public enum class CvPlotType { None = -1, Mountains, Hills, Plains, Water };

    public ref class CvPlotConnection
    {
        ...
        property CvPlotType^ Type { CvPlotType^ get() { return (CvPlotType)mTargetSimPlot->type(); } }
        ...

    };

    The property above is seen as an "System.Enum" type when referenced in a C# project.  I have to explicitly cast the c# variable as follows (GeoSimCoreController.Plot(x, y) returns a CvPlotConnection handle):

    CvPlotType type = (CvPlotType)GeoSimCoreController.Plot(x, y).Type

    What is going on here?  I am really annoyed that the managed assembly does not cast the Type property properly.



    • Edited by primem0ver Thursday, July 14, 2016 4:23 AM
    Thursday, July 14, 2016 4:21 AM

Answers

All replies