Topic: (!) templated classes with templated base classes...
Author: dHarrison@worldnet.att.net (Doug Harrison)
Date: 1998/07/27 Raw View
On 24 Jul 1998 15:20:08 GMT, ncm@nospam.cantrip.org (Nathan Myers)
wrote:
>It is. This is a big change to what most people are used to, but
>it is absolutely necessary if templates are to be understandable
>at all. To see why, consider what happens if somebody specializes
>the base class template so that it has different members.
But if I'm deriving from A<T>, and in my derived class I say the
non-dependent "fun()", I'm usually trying to call A<T>::fun(), whose
primary template is normally available to me in full. I can look into
A<T> as I write my derived class template, just as I look into
non-template bases. I don't see why it wouldn't be preferable for the
compiler to look into A<T> and sort of "semi-bind" A<T>::fun(), if
it's there. Then it would be an error if some later specialization of
A<T> didn't provide a compatible fun(). If there is no A<T>::fun(),
then the compiler would bind it as it does currently. This would seem
to break a lot less code than the new rule, and it would allow one to
write such templates a lot more naturally. I'd be interested to hear
reasons why this wouldn't be a good idea.
--
Doug Harrison
dHarrison@worldnet.att.net
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/07/24 Raw View
William Bardwell <wbardwel@platinum.com> wrote:
>in 14.6.2 (in a draft of the standard) it says:
> ...
>This appears to mean that basically a templated class with a templated
>base class can't use normal syntax to get at the parent classes
>variables and functions ...
> But this seems totally counter to normal inheritance syntax,...
It is. This is a big change to what most people are used to, but
it is absolutely necessary if templates are to be understandable
at all. To see why, consider what happens if somebody specializes
the base class template so that it has different members.
>Now, I have code that is sort of like the enclosed example, and it works
>fine on all the compilers I tried except for HP's aCC, and they
>suggested the this-> or baseclass:: thing, citing the above part of the
>standard...
HP's aCC is absolutely right. Your other compilers are wrong.
However, if a<T,U> derives from baseclass<T,U>, it's bound to be more
convenient and safer to say "a::" than to say "baseclass<T,U>::" for
those names which cannot be used with the "this->" syntax.
I wish HP's compiler would suggest that alternative.
--
Nathan Myers
ncm@nospam.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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]