Has anyone found the need to declare the return parameter of a copy assignment operator const?

前端 未结 7 2074
误落风尘
误落风尘 2020-12-14 12:02

The copy assignment operator has the usual signature:

    my_class & operator = (my_class const & rhs);

Does the following signatur

7条回答
  •  醉话见心
    2020-12-14 12:57

    Don't do that. It prevent a client from writing something like:

    (a = b).non_const_method();
    

    instead of the longer form:

    a = b;
    a.non_const_method();
    

    While you may not like the shorthand style, it's really up to the user of the library to decide how they want to write the code.

提交回复
热议问题