“using namespace” in c++ headers

后端 未结 9 2180
失恋的感觉
失恋的感觉 2020-11-22 01:32

In all our c++ courses, all the teachers always put using namespace std; right after the #includes in their .h files. This seems to me

9条回答
  •  情深已故
    2020-11-22 02:07

    Like all things in programming, pragmatism should win over dogmatism, IMO.

    So long as you make the decision project-wide ("Our project uses STL extensively, and we don't want to have to prepend everything with std::."), I don't see the problem with it. The only thing you're risking is name collisions, after all, and with the ubiquity of STL it's unlikely to be a problem.

    On the other hand, if it was a decision by one developer in a single (non-private) header-file, I can see how it would generate confusion among the team and should be avoided.

提交回复
热议问题