difference between static const and const at the namespace level



 DEVELOP > c-Plus-Plus > difference between static const and const at the namespace level

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "cppsks"
Date: 10 Feb 2005 09:18:33 AM
Object: difference between static const and const at the namespace level
namespace test
{
static const int num = 10;
const int num2 = 20;
}
What exactly is the difference here? Which is preferred (if both mean the
same)?
.

User: "Andrey Tarasevich"

Title: Re: difference between static const and const at the namespace level 10 Feb 2005 12:20:24 PM
cppsks wrote:

namespace test
{
static const int num = 10;
const int num2 = 20;
}

What exactly is the difference here?

Absolutely none.

Which is preferred (if both mean the same)?

The second form, probably. It is shorter.
If you were trying to create a header file that is compilable in both C
and C++ code, then maybe it would make sense to use the explicit
'static', since in C constant objects have external linkage by default.
But apparently you are not trying to do that.
--
Best regards,
Andrey Tarasevich
.

User: "Victor Bazarov"

Title: Re: difference between static const and const at the namespace level 10 Feb 2005 09:44:37 AM
cppsks wrote:

namespace test
{
static const int num = 10;
const int num2 = 20;
}

What exactly is the difference here? Which is preferred (if both mean the
same)?

There is no difference. I actually prefer no 'static' in this case.
'static' forces internal linkage. Since const objects that don't have
'extern' specifier have internal linkage by default, 'static' become
superfluous in a declaration/definition of a const object.
V
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER