TITLE: Using typedefs with templates PROBLEM: John Townsend Is there any way to create a compile-time alias of a template class, perhaps by using a typedef of some sort? template class Foo { // member declarations }; template typedef Foo Bar; // doesn't work [...] I also don't think that deriving Bar from Foo is the answer, since this would create an entirely distinct class. Any suggestions? RESPONSE: jamshid@ses.com (Jamshid Afshar) Not any that you haven't thought of. Stroustrup's new _The Design and Evolution of C++_ (absolutely fascinating, 4 thumbs up, and may I be the first to quote from it in an article and suggest the acronym D&E?): 15.8 Composition Techniques [...] template class List2 : public List< List > {}; [...] Allowing assignemnt [of a List> and List2] in both directions would require a language extension to allow the introduction of genuine parameterized synonyms. For example: template typedef List< List > List4; [...] This extension is technically trivial, but I'm not sure how wise it would be to introduce yet another renaming feature. At least now you know others have thought about it (and are still considering it?). I've been using the following technique for a while it two different situations: template class Bar : public Foo { typedef Foo inherit; public: Bar() {} Bar(const inherit& f) : inherit(f) {} inherit::operator=; }; struct X { Foo f(); } // X doesn't use "typedef" int g(X& x) { Bar b = x.f(); // g() does use "typedef" } This is by no means perfect. It doesn't allow a Bar& to be initialized with a Foo. If Foo has a special ctor you would have to redeclare it in Bar (access declarations for ctors would have been nice, or maybe the new template member functions could be used). It's also inefficient on compilers which don't have the sense to optimize construction and assignment. You have to declare ~Foo virtual if you ever expect to delete a Foo new'd as a Bar (it would work anyway under most compilers, but it's not required to). Although I do use the workaround and think it's ugly, I don't know if I would fight for real template typedefs because two template features were recently accepted by ANSI/ISO allow me to do what I want much more easily and clearly. Btw, the features are default template arguments and template members: template > class List {/*...*}; template class Ptr { public: template operator Ptr(); // Ptr => Ptr }; [...]