Topic: The templates - Are they well defined?


Author: daniels@biles.com (Brad Daniels)
Date: Tue, 23 Aug 1994 15:40:32 GMT
Raw View
In article <CuzsHI.K26@aston.ac.uk>, H ZHU <zhuh@aston.ac.uk> wrote:
...
>// template.h -- template declarations
>template<class T> class B
>   {public: virtual T operator()(const T &) = 0;};
>template<class T> class D1 : public B<T>
>   {public: T operator()(const T &);};
>template<class T> class D2 : public B<T>
>   {public: T operator()(const T &); };
>template<class T> D2<T> operator+(const B<T> &, const B<T> &);

This last line is where you run into trouble.  As most (all?) compilers
currently interpret things, the template function above will only work
on two objects of class B<T>, not on objects of a class which inherits
from B<T>.  This is because of the "exact match" rule in the ARM.

I believe the current draft of the working paper may allow this case, but
since I don't have an up-to-date copy, I can't be sure.  Anyway, your example
is not legal according to the currently-implemented definition of the language.

- Brad
-----------------------------------------------------------------------------
+ Brad Daniels           | "If anyone finds this offensive, I am prepared   +
+ Biles and Associates   |  not only to retract my words, but to deny under +
+ My views, not B&A's    |  oath that I ever said them." - Tom Lehrer       +
-----------------------------------------------------------------------------