CompuServe Messages

C++ question

    22-Oct-92 22:02:00
Sb: #29490-C++ question
Fm: Thomas A. Elam 72607,654
To: Greg Comeau@Comeau Cmptg 72331,3421
>>There are at least two ways to make a type-safe list class from a >>list-class template. One is to instantiate a general-purpose template >>class such as Slist as a list of type-safe pointers….. >>//… >>template<class T> class Tlink : public slink { // … >>template<class T> class Slist : private slist_base { // … >>main() { Slist<int*> iplist; } > >What makes this type safe is that Slist get() operations *must* be using the >… > >>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. >>template<class T> >>class Splist : private Slist<void*> { >> void insert(T* p) { Slist<void*>::insert(p); } // …. > >Now he is "optimizing" for pointers, since pointer are things C and C >… I finally understood when Mr. Stroustrup (in message 2995 in the c.plus.plus/beginner forum on BIX) stated that "… there is no (significant) difference …. However, in a a typical program we will use lists of many kinds of pointers…. Unfortunately, this would imply generating [many] variants of the Slist code … On the other hand if we used … Splist<…> … the [many] types [of Slist] would all share the Slist<void*> implementation…. … for many (most?) real projects the saving in space is significant." Sorry, you probably said it too, but I just didn't get it. Anyway, the intellectual satisfaction for me of under- standing this is intense, and you helped get me on the right track. Thank you very much.