Operator overload of << needs const; produces headache

前端 未结 4 1104
天命终不由人
天命终不由人 2021-01-24 21:54

I am trying to overload operator <<, but it always need to be a const function. However, I want to change values inside this overloaded function

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-24 22:00

    You're implementing operator<< as an inserter into our Check object here. In this case, it looks like the right solution is to just have your insertion operator actually be non-const, since it would be nonsensical to use it on a const object (because it's mutating logical object state).

提交回复
热议问题