在C ++中'return * this'是什么意思? [英] What does 'return *this' mean in C++?

查看:457
本文介绍了在C ++中'return * this'是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个C ++程序转换为C#,但这部分让我困惑。返回*是什么意思?

I'm converting a C++ program to C#, but this part has me confused. What does return *this mean?

template< EDemoCommands msgType, typename PB_OBJECT_TYPE >
class CDemoMessagePB : public IDemoMessage, public PB_OBJECT_TYPE
{
    (...)
    virtual ::google::protobuf::Message& GetProtoMsg()  { return *this; }
}

如何转换为C#?

推荐答案

表示指向对象的指针,因此 * this 是一个对象。所以你返回一个对象,即 * this 返回对对象的引用。

this means pointer to the object, so *this is an object. So you are returning an object ie, *this returns a reference to the object.

这篇关于在C ++中'return * this'是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆