Topic: Member function template does not override virtual fcn.
Author: Email_To::.Hans.Olsson@dna.lth.se (Hans Olsson)
Date: 1998/08/18 Raw View
The draft standard (and likely the actual standard --- although I haven't
seen it) states that a member function template cannot be made virtual
and furthermore does not override the corresponding function in a base-class.
I understand that allowing virtual member function templates would
not work well with vtables (basically the vtable in the base-class
would have to be constructed during linking).
But why does a member function template not override (non-template) virtual
functions in the base-class? The vtable-argument does not hold, but
are there any other good arguments?
The reason for wanting it is basically examples such as
(but with different matrices instead of float/double):
class MathOp {
public:
virtual float f(const float&x) const=0;
virtual double f(const double&x) const=0;
virtual long double f(const long double&x) const=0;
};
class Erf : public MathOp {
// Implement the different overloaded functions to get the right
// precision.
public:
float f(const float&x) const {....}
double f(const double&x) const {....}
long double f(const long double&x) const {...}
};
class Log : public MathOp {
public:
template<class T> T f(const T&x) const {return log(x);}
// Does not override f in MathOp, must add extra functions to achieve this.
};
--
// Home page http://www.dna.lth.se/home/Hans_Olsson/
// Email To..Hans.Olsson@dna.lth.se [Please no junk e-mail]
[ 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 ]