简体   繁体   中英

how to declare public class

I am so sorry for the question that sounds so stupid :)

I have such line of code:

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

And I can not use ValueMessageBuilder from my c# project because of this error:

Cannot access internal struct 'ValueMessageBuilder' here.

So I've tried to make it public and recompile dll:

public class ValueMessageBuilder : public Common::Logger

But compilation failed with such error 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

So the question is how to convert internal ValueMessageBuilder structure to public?

As the error states your code must be compiled with /clr option (Project properties | General | Common Language Runtime Support). after that your project will become c++/clr (managed c++). Also I think the class should be preceded with ref keyword to be visible in c#.

For a class to be usable from C#, it needs to be a managed type with .NET metadata.

Use either ref class or value class .

Note that an object can't contain both managed and native class types. However, a native class can hold a handle to a managed instance (use gcroot ) and a managed type can hold a pointer to a native object ( My smart pointer, posted on codereview, may help with lifetime management ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM