There are several options. The first thing that came to my mind was that C ++ allows the static members of these class templates to define more than one translation unit:
template<class T>
struct dummy {
static int my_global;
};
template<class T>
int dummy<T>::my_global;
inline int& my_global() {return dummy<void>::my_global;}
The component combines several definitions into one. But only inlinecan also help here, and this solution is much simpler:
inline int& my_global() {
static int g = 24;
return g;
}
. ++ , , , . , .