What is the difference between declaring a static constant and a constant in an unnamed namespace?

As I know, there are two ways to declare a constant variable that is visible in only one file:

  • Announce static const int VARIABLE = 1
  • Declare it in an unnamed namespace:
namespace { const int VARIABLE = 1; }

And what's the difference?

+4
source share
1 answer

Since he is const, both have an internal connection, and there is no difference. Therefore, we consider a more interesting case when it is not const.

In this case, in practice, there are few differences.

, , ; , , .

+3

Source: https://habr.com/ru/post/1540370/


All Articles