0

我很抱歉这个听起来很愚蠢的问题:)

我有这样的代码行:

namespace Messages{
/// @brief Interface to support building a message during decoding.
class ValueMessageBuilder : public Common::Logger
....

ValueMessageBuilder由于此错误,我无法从我的 c# 项目中使用:

Cannot access internal struct 'ValueMessageBuilder' here.

所以我试图将其公开并重新编译dll:

public class ValueMessageBuilder : public Common::Logger

但是编译失败并出现此类错误Error C3381: 'QuickFAST::Messages::ValueMessageBuilder' : assembly access specifiers are only available in code compiled with a /clr option F:\Oleg\quickfast_1_4_0_my\src\Messages\ValueMessageBuilder.h 17 1 QuickF‌​AST

那么问题是如何将内部ValueMessageBuilder结构转换为公共结构?

4

2 回答 2

0

由于错误表明您的代码必须使用 /clr 选项(项目属性 | 常规 | 公共语言运行时支持)进行编译。之后,您的项目将变为 c++/clr(托管 c++)。另外我认为该类应该以ref关键字开头,以便在 c# 中可见。

于 2012-04-29T14:51:56.707 回答
0

对于可从 C# 使用的类,它必须是具有 .NET 元数据的托管类型。

使用ref classvalue class

请注意,对象不能同时包含托管类和本机类类型。但是,本地类可以持有托管实例的句柄(使用gcroot),托管类型可以持有指向本地对象的指针(我的智能指针,发布在 codereview 上,可能有助于生命周期管理)。

于 2012-04-29T14:59:39.457 回答