Topic: Borland templates (AAUGH!)
Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Fri, 17 Sep 1993 23:29:17 GMT Raw View
In article <2792mn$dsk@techbook.techbook.com> deef@techbook.techbook.com (Derek Foster) writes:
>I am trying to declare some structures of the following nature:
>
>template <class T> class ListElem
>{
> ListElem<T> * next;
> T data;
>}
>template <class T> class ListIterator
>{
> typedef ListElem<T> Elem;
> Elem * ptr;
>}
>class ListElement
>{
> ListIterator<ListElement> iter;
>}
>
>Borland C++ 3.1 won't seem to let me do this -- it gives me an error
>along the lines of "size of ListElement is undefined" in the "T data" line
>of the source file. It seems to me that the compiler shouldn't even be
>trying to expand the template for ListElem, since my only reference to the
>ListElem type is to a POINTER to the type. I thought that the typedef might
>be causing problems, so I removed it, but the problem still remained.
As far as the ARM is concerned, the conditions under which a template will
actually be instantiated are (I think) totally unspecified. Most people
expect that code like:
template <class T> class TMPL { /* ... */ };
TMPL<int> object;
will cause the template to be instantiated (in full?) but (contrary to
popular belief) the C++ standardization committee seems to be leaning
in the direction of saying that such code SHOULD NOT cause a "complete"
instantiation of the template, and that it should instead cause some
sort of partial instantiation (an odd notion if I ever heard of one)
under which some of the *members* of TMPL (e.g. the function members)
do not in themselves get instantiated.
I believe that the final rules which will govern such cases have not yet
been completely worked out (and voted on) in the C++ standardization
committee. If anyone has more up-to-date information than I do, please
post it.
>I have had numerous problems of this nature, and have discovered very
>strange circumstances wherein, for example, constructs like this compile
>just fine:
>
>template <class T> class tempclass;
>class someclass
>{
> tempclass<someclass> * x;
>};
>
>but if the actual definition of class tempclass is included (even AFTER the
>declaration of class someclass), like so:
>
>template <class T> class tempclass {T x;}
>
>the declaration of class someclass now WON'T compile. The template is
>expanded by the declaration of class someclass, (which I still think
>shouldn't happen), and since the size of an object of type tempclass depends
>on the size of class someclass (which is undefined while someclass is being
>defined), the compilation fails. Experimentation with #pragma option -Jgx,
>etc. has failed to solve the problem.
>
>Is this a bug in Borland, or does the ARM say this is OK?
Once again, I would emphasize that (as far as I know) neither the ARM nor
the current X3J16 working paper give precise rules which would make it
possible for us to *either* say that Borland is doing it wrong, or that
Borland is doing it right. These questions simply haven't been settled yet.
Follow-ups to comp.std.c++ please.
--
-- Ronald F. Guilmette ------------------------------------------------------
------ domain address: rfg@netcom.com ---------------------------------------
------ uucp address: ...!uunet!netcom.com!rfg -------------------------------