Overloading operator << - C++

后端 未结 7 1667
Happy的楠姐
Happy的楠姐 2021-02-10 07:25

Background

I have a container class which uses vector internally. I have provided a method AddChar(std::string) to this wrap

7条回答
  •  日久生厌
    2021-02-10 08:02

    1) Yes, except since AddChar is public there's no reason it needs to be a friend.

    2) This is arguable. << is sort of in the position of being the operator whose overloading for "weird" things is at least grudgingly accepted.

    3) Nothing obvious. As always, profiling is your friend. You may want to consider passing the string parameters to AddChar and operator<< by const reference (const std::string&) to avoid unnecessary copying.

提交回复
热议问题