Udostępnij za pośrednictwem


make_public

Indicates that a native type should have public assembly accessibility.

#pragma make_public(type)

Parameters

type is the name of the type you want to have public assembly accessibility.

Remarks

make_public is useful for when the native type you want to reference is from a .h file that you cannot change. If you want to use the native type in the signature of a public function in a type with public assembly visibility, the native type must also have public assembly accessibility or the compiler will issue a warning.

make_public must be specified at global scope and is only in effect from the point at which it is declared through to the end of the source code file.

The native type may be implicitly or explicitly private; see Type Visibility for more information.

Example

The following sample is the contents of a .h file that contains the definitions for two native structs.

// make_public_pragma.h
struct Native_Struct_1 { int i; };
struct Native_Struct_2 { int i; };

The following code sample consumes the header file and shows that unless you explicitly mark the native structs as public, using make_public, the compiler will generate a warning when you attempt to use the native structs in the signature of public function in a public managed type.

// make_public_pragma.cpp
// compile with: /c /clr /W1
#pragma warning (default : 4692)
#include "make_public_pragma.h"
#pragma make_public(Native_Struct_1)

public ref struct A {
   void Test(Native_Struct_1 u) {u.i = 0;}   // OK
   void Test(Native_Struct_2 u) {u.i = 0;}   // C4692
};

See Also

Reference

Pragma Directives and the __Pragma Keyword