CompuServe Thread

C++ question, continued

1 messages in this thread
#29404From: Thomas A. ElamOct 20, 1992 10:57 AM
[Continued] template<class T> class Tlink : public slink { public: T info; Tlink(const T& a) : info(a) {} }; template<class T> class Slist : private slist_base { public: void insert(const T& a) { slist_base::insert(new Tlink<T>(a)); } }; main() { Slist<int*> iplist; } ————————— cut here —————————- A second way to make a type-safe list class from a list-class template is to build a list-of-void* class template from the above Slist, then instantiate the list-of-void* template class as a list of type-safe pointers. The following is a compilable example (missing just the class templates from the first example): ————————— cut here —————————- template<class T> class Splist : private Slist<void*> { public: void insert(T* p) { Slist<void*>::insert(p); } }; main() { Splist<int> iplist; int i1 = 1, i2 = 2; iplist.insert(&i1); iplist.insert(&i2); } ————————— cut here —————————- It looks to me like Stroustrup is saying Splist<int> iplist; is better than Slist<int*> iplist; Is it better, and, if so, why? [More]