Why not overload operator+=() for std::vector?

前端 未结 4 1785
别那么骄傲
别那么骄傲 2020-12-06 16:18

I\'ve started learning C++, so I don\'t know in my lack of knowledge/experience why something so seemingly simple to a rookie as what I\'m about to describe isn\'t already i

4条回答
  •  庸人自扰
    2020-12-06 16:53

    In addition to what others mentioned about this syntax not being intuitive and therefore error prone, it also goes against a good design rule making general algorithms applied to various containers free functions, and container specific algorithms -- member functions. Most containers follow this rule, except std::string, which got a lot of flack from Herb Sutter for its monolithic design.

提交回复
热议问题