C++ Class template Separating a Template from Function Code
#include <iostream> using namespace std; template <typename T> class MyClass//from w w w . jav a2s . co m { protected: T x; public: T& getx(); void setx(T); }; template <typename T> T &MyClass<T>::getx() { return x; } template <typename T> void MyClass<T>::setx(T newx) { x = newx; } int main() { MyClass<int> separate; separate.setx(10); cout << separate.getx() << endl; return 0; }