我正在将一个C++程序转换为C#,但这部分让我感到困惑.什么回报*这意味着什么?
template< EDemoCommands msgType, typename PB_OBJECT_TYPE >
class CDemoMessagePB : public IDemoMessage, public PB_OBJECT_TYPE
{
(...)
virtual ::google::protobuf::Message& GetProtoMsg() { return *this; }
}
Run Code Online (Sandbox Code Playgroud)
它将如何转化为C#?
小智 11
当心,如果您尝试使用return *this;
的返回类型是一个函数Type
,而不是Type&
,C++会尽量使对象的副本,然后立即调用析构函数,通常不是预期的行为.因此,返回类型应该是您的示例中的引用.