1

I was reading a book and I have some ambiguities about linkage into namaspaces.

As far as I read,

When you are in a situation where you need to declare global symbols as statics to avoid linkage problems, prefer to use unnamed namespaces

Ok So inside an unnamed namespace what is defined will have internal linkage (like using static in global namespace).

Then the write added :

Template arguments cannot be names with internal linkage, so using static variables is not possible.

Ok till now.

On the other hand, symbols in an unnamed namespace have external linkage and can be used as template arguments.

So here I am lost, is the content of an unnamed namespace will have internal or external linkage ?

#include <iostream>
template <int const& Size>
class test {};

static int Size1 = 10;

namespace
{
    int Size2 = 10;
}  

int main(void)
{
    test<Size1> t1; // said here gonna produce a compile error but was not the case
    test<Size2> t2;

    return 0;
}

And what about the case of normale namespace (named namespace).

Thank you.

Blood-HaZaRd
  • 2,049
  • 2
  • 20
  • 43

0 Answers0