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

后端 未结 6 579
盖世英雄少女心
盖世英雄少女心 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 16:47

    Watch out that if you try to use return *this; on a function whose return type is Type and not Type&, C++ will try to make a copy of the object and then immediately call the destructor, usually not the intended behaviour. So the return type should be a reference as in your example.

提交回复
热议问题