December 2021
Intermediate to advanced
352 pages
9h 32m
English
using namespace at global scope in a header filePlease, don’t do this. Ever.
Never. Not ever. Not even once.
Please.
The Core Guidelines document offers the following example:
// bad.h
#include <iostream>
using namespace std; // bad <- "You're not kidding," says Guy
// user.cpp
#include "bad.h"
// some function that happens to be named copy
bool copy(/*... some parameters ...*/);
int main()
{
// now overloads local ::copy and std::copy, could be ambiguous
copy(/*...*/);
}
“Bad” is an understatement. We know it seems we are belaboring the point, but this example only exposes part of the horror.
There is one and only one global namespace. From the standard, ...
Read now
Unlock full access