What's the purpose of the unnamed namespace?

Posted by bbazso on Stack Overflow See other posts from Stack Overflow or by bbazso
Published on 2010-05-04T15:45:13Z Indexed on 2010/05/04 15:48 UTC
Read the original article Hit count: 140

Filed under:

In a .cpp file, if I decare a constant as follows:

namespace
{
   const int UDP_PORT_MIN = 1024;
   const int UDP_PORT_MAX = 65535;
}

vs. just:

const int UDP_PORT_MIN = 1024;
const int UDP_PORT_MAX = 65535;

What's the difference between these two?

I often see constant definitions declared in an unnamed namespace, so I was wondering what's the purpose of the unnamed namespace in this context?

© Stack Overflow or respective owner

Related posts about c++