TITLE: Recursive templates PROBLEM: Joshua Lam [Part 1] template class MyClass { public: MyClass(){} MyClass *another; // note the X and Y are flipped // can I do this??? }; [Part 2] MyClass* a = new MyClass; MyClass* b = new MyClass; a->another = b; // compiler complains here!!! RESPONSE: jamshid@emx.cc.utexas.edu (Jamshid Afshar), 6 Sep 93 [Part 1] Yes, that's legal. Some compilers have problems, though, with the use of "recursive" templates like this. Recursive template examples which I believe are or should/will be legal include: 1) template class Array { //... public: Array operator[](int index); // operator[] return type should only expand when func. called }; 2) template class Envelope : public Letter {/*...*/}; class String { public: Envelope operator+(const char*); }; 3) template class Iter { Container* container; Container::IterState state; }; template class List { public: typedef Iter > MyIter; typedef int IterState; // typedefs should be parsed on an "as-needed" basis }; List::MyIter i; 4) template struct Promote : Promote {}; struct Promote { typedef complex Result; }; complex c; double d; Promote r = c+d; The premise is that templates classes, temlate member/friend function return and parameter types, and typedefs and classes nested in template classes should be expanded on an "as-needed", incremental basis to allow for recursive templates and specializations. [Part 2] You probably are using Cfront 3.0.1 which had a lot of problems. BC++ 3.1, gcc 2.4.5 and Cfront 3.0.2 accept your code.