// template_class_static.cc #include using namespace std; // oversimplified template class example where the class doesn't // even really depend on typename, but the point is to show // how template classes work with static member data template class MyClass { public: static int S; }; // static data has to be declared outside the class // here's how we do it, even though in this case the // static data is always an int and doesn't depend on typename template int MyClass::S; int main() { MyClass IntClass; MyClass IntClass2; IntClass.S = 1; MyClass DoubleClass; DoubleClass.S = 99; cout << "IntClass static value = " << IntClass.S << endl; cout << "IntClass2 static value = " << IntClass2.S << endl; cout << "DoubleClass static value = " << DoubleClass.S << endl; }