// template_class.cc #include using namespace std; template class MyClass { private: T Val; public: void SetVal(const T& x) { Val = x; } const T& GetVal() const { return(Val); } // function above is const function: does not change obj // returns const ref, meaning we can't change the value // even though GetVal() is giving us a ref }; int main() { MyClass I; // specify what type to use with <> I.SetVal(42); std::cout << "I holds value " << I.GetVal() << endl; MyClass D; D.SetVal(3.1415926); std::cout << "D holds value " << D.GetVal() << endl; }