home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!cs.utexas.edu!hellgate.utah.edu!fcom.cc.utah.edu!swillden
- From: swillden@news.ccutah.edu (Shawn Willden)
- Subject: "Recursive" template problem
- Message-ID: <1992Sep2.150611.15090@fcom.cc.utah.edu>
- Sender: news@fcom.cc.utah.edu
- Organization: University of Utah Computer Center
- X-Newsreader: Tin 1.1 PL3
- References: <1992Aug31.155313.5879@fcom.cc.utah.edu>
- Date: Wed, 2 Sep 92 15:06:11 GMT
- Lines: 44
-
- To any of you who already saw my first post on this subject, I apologize.
- However, given the resounding silence that post elicited (no one even
- corrected my syntax errors!), I thought maybe I had better try again,
- with a different subject (specifically with one that doesn't include
- 'BC' - since that was in my own kill file for quite some time).
-
- The problem is this: Given a template base class that contains pointers
- to two of its derived classes, at least two compilers (gcc-2.2.2 and BC++
- 3.1) choke (the former dumps core, the latter reports an error). The
- code looks something like this:
-
- // Forward declarations of A1<T> and A2<T>
- template<class T> class A1;
- template<class T> class A2;
-
- // Now we'll do the actual class definitions.
- template<class T> class A {A1<T>* a; A1<T>* b;};
- template<class T> class A1 : public A<T> {};
- template<class T> class A2 : public A<T> {};
-
- int main() {A1<int> myA1;}
-
- What happens is, the compiler:
- begins to expand A1<int>,
- realizes it needs A<int> first,
- begins to expand A<int>,
- *thinks* it needs to expand A2<int> (which it doesn't, because b is
- and A2<int>*),
- begins to expand A2<int>,
- realizes it needs A<int> first,
- notices that A<int> is partially expanded
- and pukes.
-
- So, has anyone else seen this problem? Come up with a work-around? If I
- get some time I'm going to try to fix gcc but my archie server doesn't
- seem to find anything under BC++3.1_source_code.tar.Z ;-) that one's going
- to be a little tougher. Are there any compilers that *do* handle this?
- (I only have access to gcc 2.2.2, BC++ 3.1 and some version of Oregon C++
- that doesn't support templates [The man page says the -Xv switch tells
- Oregon C++ to report what version it is, but it doesn't work]).
-
- --
- Shawn Willden
- swillden@icarus.weber.edu
-