///////////////////////////////////////////////////////////////////// // TemplTemplParam.cpp // // - Illustrates use of template template parameters // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2004 // ///////////////////////////////////////////////////////////////////// #include #include template class Widget { public: Widget(const T& t) : _t(t) {} T& value() { return _t; } private: T _t; }; template class container { public: void add(const Object &ob) { Objs.push_back(ob); } Object& operator[](int n) { return Objs[n]; } unsigned int size() { return Objs.size(); } private: std::vector Objs; }; ///////////////////////////////////////////////////////////////////// // template with template parameter // - its odd, but typename does not work here // - user will instantiate with containerTTP // where T and Object are a type and template respectively template < class T, template class Object > class containerTTP { public: void add(const Object& ob) { Objs.push_back(ob); } Object& operator[](int n) { return Objs[n]; } unsigned int size() { return Objs.size(); } private: std::vector< Object > Objs; }; // ///////////////////////////////////////////////////////////////////// // template with template parameter, version 2 // - template parameter isn't used in class or is explicitly specified // - user instantiates as PolicyUser template