Type visibilty for a header Share a header file shared between native and managed clients

蹲街弑〆低调 提交于 2019-12-20 07:22:22

问题


I have a header file that is included by both a native cpp file and a managed cpp file(compiled with /clr). It includes only native types, but I want to specify that the native types are visible outside the assembly
(see http://msdn.microsoft.com/en-us/library/4dffacbw(VS.80).aspx).

Essentially, I want:

public class NativeClass  // The public makes this visible outside the assembly.
{

};

If I include this code from a native cpp, I get the following error:

error C3381: 'NativeClass' : assembly access specifiers are only available in code compiled with a /clr option

Attempted solution:

I'm currently using a preprocessor solution that causes the public to appear when compiling with the managed client, but it does not appear for the native client:

#ifdef __cplusplus_cli
#define CLR_ASSEMBLY_ACCESS_SPECIFIER__Public public
#else
#define CLR_ASSEMBLY_ACCESS_SPECIFIER__Public 
#endif 

CLR_ASSEMBLY_ACCESS_SPECIFIER__Public
class NativeClass      
{

};

Question:

Is this the appropriate way to achieve this, or is there a better way?


回答1:


Have you tried the make_public pragma listed on the MSDN page you linked to?

Otherwise, the solution you have is perfectly valid. I'm curious to know why you want to export native types from a CLR assembly though.



来源:https://stackoverflow.com/questions/4121422/type-visibilty-for-a-header-share-a-header-file-shared-between-native-and-manage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!