You could always move the static variable to inside the get function:
#include <Carbon/Carbon.h> #include <iostream>
template<typename T> class t { public: const char* getFoo(); };
template<typename T> const char* t<T>::getFoo() { static char *foo = "default"; return foo; }
// specializations typedef t<char> c1; template<> const char* t<char>::getFoo() { static char *foo = "foo1"; return foo; }
typedef t<float> c2; template<> const char* t<float>::getFoo() { static char *foo = "foo2"; return foo; }
int main (int argc, char * const argv[]) { c1 obj1; c2 obj2; std::cout << obj1.getFoo() << " - " << obj2.getFoo() << std::endl; return 0; }
Side note: std::endl flushes the buffer. Calling flush afterwards is redundant. Adin Hunter Baber
"The more I learn, the more I learn how little I know." -- Socrates |