Pergunta de entrevista da empresa Bloomberg

How are static members of a template class shared?

Respostas da entrevista

Sigiloso

27 de jul. de 2010

They are shared amongst same types.

2

Sigiloso

8 de nov. de 2011

For each instantiation of the template class the static members are shared only between the objects of that class and are completely independent from static members of other instantiations of the template class. E.g. this program prints "50": #include template class A { public: static int x; }; template int A::x = 0; int main() { A a; A b; a.x = 5; std::cout << a.x << b.x << std::endl; return 0; }

1