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

后端 未结 6 572
盖世英雄少女心
盖世英雄少女心 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条回答
  •  隐瞒了意图╮
    2020-12-13 17:05

    Like in C# this is an implicit pointer to the object you are currently using.
    In your particular case, as you return a reference & to the object, you must use *this if you want to return the object you are currently working on.
    Don't forget that a reference takes the variable itself, or in case of a pointer (this), the object pointed to (*this), but not the pointer (this).

提交回复
热议问题