Alex Rivera | Logout

root namespace coding convention in C++

Asked 2011-03-23T11:55:11.230
10

Would you recommand prefixing global namespaces with ::? (for instance ::std::cout instead of std::cout) Why? Is it faster to parse for the C++ compiler?

Thanks.

Edit
Report

1 Answer

5

It has nothing to do with parsing speed. C++ uses Argument-dependent name lookup - Koenig Lookup and when you have to make sure that the compiler uses the symbol from the global root namespace you prefix it with ::. If you don't the compiler might also use function definitions from other namespaces when it sees fit (depending on the lookup method).

So, it is better not to do it unless you have to.

answered 2011-03-23T12:00:30.173

Your Answer