TITLE: templates 101 (Newsgroups: comp.lang.c++, 22 Sep 97) KOH: Shannon Koh > Has anyone ever wondered about the inheritance of template classes? BJARNE: bs@research.att.com (Bjarne Stroustrup) Yes, someone has :-) KOH: > Can a template class inherited from a normal class? BJARNE: Yes: class B { ... }; template class X : public B { ... }; KOH: > Or can a normal class inherit from a template class? BJARNE: No, if you mean this: class D1 : public X { ... }; // error X is a template (not a class) Yes, if you mean this: class D2 : public X { ... }; // X is a class KOH: >How about one template class inheriting from another template class, BJARNE: Yes: template class X2 : public X { ... }; KOH: > and better still, with different template classes? BJARNE: Yes, if you mean something like this: template class Z { ... }; template class X3 : public X, public Z { ... }; You can even have a template class inherit from one of its template parameters: template class X4 : public T { ... }; KOH: > Seeking all who know and have experienced... Bye! BJARNE: Hmm. That's quite a lot of people. Actually, the real question is not just what you can do, by why you would want to do it. That is, what are good uses of the constructs presented above? For some answers to many such questions, see Stroustrup: The C++ Programming Language (3rd Edition) and also Stroustrup: The Design and Evolution of C++ There are information about these books on my homepages. - Bjarne Bjarne Stroustrup, AT&T Labs, http://www.research.att.com/~bs