Bloomberg Interview Question

How are static members of a template class shared?

Interview Answers

Anonymous

Jul 27, 2010

They are shared amongst same types.

2

Anonymous

Nov 8, 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