Which namespace does operator<< (stream) go to?

后端 未结 4 1007
慢半拍i
慢半拍i 2021-02-19 06:01

If I have have some overloaded ostream operators, defined for library local objects, is its okay for them to go to std namespace? If I do not declare them in std namespace, then

4条回答
  •  萌比男神i
    2021-02-19 06:33

    It is generally a bad practice to declare anything (types, operators, etc ...) to be a part of a namespace you do not own. This can have unexpected consequences for people consuming your library. A better solution is to define your own namespace and to import both std and your namespace when you need to combine solutions.

提交回复
热议问题