Pregunta

Retaining the names inside namespace will make compiler work less stressful!?

For example:

// test.cpp
#include</*iostream,vector,string,map*/>
class vec { /* ... */ };

Take 2 scenarios of main():

// scenario-1
using namespace std;  // comment this line for scenario-2
int main ()
{
  vec obj;
}

For scenario-1 where using namespace std;, several type names from namespace std will come into global scope. Thus compiler will have to check against vec if any of the type is colliding with it. If it does then generate error.

In scenario-2 where there is no using namespace, compiler just have to check vec with std, because that's the only symbol in global scope.

I am interested to know that, shouldn't it make the compiler little faster ?

No hay solución correcta

Licenciado bajo: CC-BY-SA con atribución
scroll top