Monday, December 22, 2008

Anonymous namespaces in C++

This is a very simple thing used just to minimize the overuse of static keyword
Any thing present in the anonymous namespace can be accessed in the same file only forcing
internal linkage and eliminating the overuse of static.

A word of caution overuse of anything is bad and the same applies to anonymous namespace also

For example consider a file
//file.cpp
namespace anonymous
{
int x;

};

int main()
{
std::cout<<"X present in this file has the value"<return 0;
}

although this x is present in the global area still has the file scope only without using the static
keyword.


No comments: