If you have a (not templated) class containing a static member, for example:
class Foo
{
public:
static int x;
};
Then it Foo::xmust be defined in one and only one translation unit, or the compiler will complain about several definitions. Therefore, in somefile.cppyou will need to define it:
int Foo::x = 10;
Thus, any translation unit that refers to Foo::xrefers to the same memory address.
But what if it Foois a class template?
template <class T>
class Foo
{
public:
static int x;
};
Now Foo<T>::xyou can define in the header file by saying:
template <class T>
int Foo<T>::x = 10;
, foo.hpp Foo, translation_unit1.cpp translation_unit2.cpp foo.hpp, Foo<T>::x Foo, ( , Foo<int>::x) ?