Re: enum versus private enum
I wouldn't expect your safe_cast to work in any version of C++/CLI or the .NET framework. This cast is meant to be used for downcasting in a descendant/ancestor relationship, i.e. casting an A ^ to a B ^ where the actual object the A ^ refers to is of type B which is derived from A, or a type derived from B. There's no such relationship between System::Int32 (for which int is a synonyme) and a managed enum. They both derive from System::ValueType, directly or indirectly, but that rather gives them some sort of uncle/nephew relationship.
There is an existing conversion between the two, however, so I think a static_cast would probably do the trick, at least for the conversion from enum to int, though I'm not actually 100% sure off the top of my head.
And I don't think the assembly-level visibility (i.e. public vs. private enum class) has anything to do with that at all.
Re: enum versus private enum
Well it doesn't seem the type of cast matters, but using private enum as opposed to just enum does matter. I'm just wondering why. I'm going through Ivor Horton's Visual C++ 2010 book and ran into this error with one of the exercises. I searched google and found the "fix" but not the reason why it had to be *private* enum in VS2012 and enum was just fine in VS2010. Its just hard to believe one would have to rewrite such simple code from one version of VC++ to the next. I can imagine intricate code would have to be completely rewritten every time a new version of Visual studio comes out. I learned on unix with GNU C many years ago, and am just surprised at how messy that is.