How to: Declare public and private on Native Classes

It is possible for a native type to be referenced from a managed type. For example, a function in a managed type can take a parameter whose type is a native struct. If the managed type and function is public in an assembly, then the native type must also be public.

Example

// mcppv2_ref_class3.h
// native type
public struct N {
   N(){}
   int i;
};

Next, create the source code file that will consume the native type:

// mcppv2_ref_class3.cpp
// compile with: /clr /LD
#include "mcppv2_ref_class3.h"
// public managed type
public ref struct R {
   // public function that takes a native type
   void f(N nn) {}
};

Next, compile a client:

// mcppv2_ref_class4.cpp
// compile with: /clr
#using "mcppv2_ref_class3.dll"

#include "mcppv2_ref_class3.h"

int main() {
   R ^r = gcnew R;
   N n;
   r->f(n);
}

See Also

Concepts

Classes and Structs (Managed)