Topic: Template instantiation
Author: "Nathan Myers, http://www.cantrip.org/" <ncm@cantrip.org>
Date: 1996/03/21 Raw View
John E. Potter wrote:
>
> I have only found one compiler which accepts the following. The others
> attempt to instantiate class N prior to completing class L. As I read
> DWP-14.3 [temp.inst], class N<int> should not be instantiated in the
> following code. It would be instantiated when some class L<int> function
> used an N<int>.
>
> template <class T> class N;
> template <class T> class L { N<T>* ptr; };
> template <class T> class N { L<T> next; };
> int main () { L<int> l; }
>
> Do I have one correct compiler that accepts it, several correct compilers
> which reject it, or (I hope not) all correct compilers because it is not
> specified?
You have one (at least semi-) correct compiler, and several broken ones.
> If the latter, is there any standard way to make this portable? I can
> change ptr to a void* and reinterpret_castrate everything, but that is
> not very pleasing.
You could change the member to a void* and provide an (inline) access
function that does the cast, in only one place. Better to use
non-broken compilers, of course.
Nathan Myers
ncm@cantrip.org http://www.cantrip.org/
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]