Posts

Showing posts with the label access

C++/CLI: Native types visibility/access

Spanish version / Versión en Español Say we have the following code in a C++/CLI assembly: //Assembly A public ref class ManagedClass{ public: ManagedClass( const NativeClass &a ); } If we wish to invoke this constructor from another C++/CLI assembly, as in this case... //Assembly B ManagedClass^ AnotherManagedClass::Property::get(){ NativeClass temp; return gcnew ManagedClass( temp ); } ... when we try to compile Assembly B, we'll get a compile error saying that the constructor we're trying to call is private. But how is that possible, if we declared it public? The answer is here . To sum it up, the workaround is using the #pragma make_public(NativeClass) directive right below the #include for NativeClass. This makes NativeClass accesible to other C++/CLI assemblies.