Ordering of using namespace std; and includes?

前端 未结 6 934
眼角桃花
眼角桃花 2020-12-02 00:04

I recently saw this code being used in a source file in a C++ project:

using namespace std;
#include 

Ignoring all issues o

6条回答
  •  无人及你
    2020-12-02 00:49

    I don't think it's legal, but the standard isn't 100% clear about it. Basically, name lookup (as defined in §3.4) can't find a previous declaration of the namespace, because there isn't one. Everything hinges on whether:

    using namespace std;
    

    is a declaration of the namespace or not. And I don't see any text in §7.3.4 which says that a using-directive declares the nominated namespace. G++ allows your code, but IMHO, this is a bug.

提交回复
热议问题