Monday, August 6, 2018

Namespace without a name in C++











I came across this code



namespace ABC {
namespace DEF {

namespace
{



I expected the namespace should be followed by some name, but it's not the case with this code.



Is this allowed in C++? What's the advantage for this unnamed namespace?


Answer



It's called an unnamed namespace / anonymous namespace. It's use is to make functions/objects/etc accessible only within that file. It's almost the same as static in C.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...