Returning *this in member functions

后端 未结 9 1296
无人共我
无人共我 2020-12-18 22:35

I recently used a library that allows the following type of syntax:

MyClass myObject;
myObject
    .setMember1(\"string value\")
    .setMember2(4.0f)
    .s         


        
9条回答
  •  情深已故
    2020-12-18 23:13

    There's no problem with this style. The only downside is that you can't use the return value for more typical purposes, like returning the result of the function.

提交回复
热议问题