What does 'return *this' mean in C++?

后端 未结 6 570
盖世英雄少女心
盖世英雄少女心 2020-12-13 16:44

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          


        
6条回答
  •  Happy的楠姐
    2020-12-13 16:47

    In your particular case, you are returning the reference to 'this', since the return type of the function is a reference (&).

    Speaking of the size of returned memory, it is the same as

    virtual ::google::protobuf::Message* GetProtoMsg()  { return this; }
    

    But the usage at call time differs.

    At call time, you will call store the return value of the function by something like:

    Message& m = GetProtoMsg();
    

提交回复
热议问题