Victor said:
Steven said:
Greg said:
But the signature of a virtual function override can declare a
different return type than the function it overrides, provided that
the return type that it does declare is a virtual subclass of the
return type of the function declared in the base. [assuming
compilation with a C++ compiler that supports "covariant return
types"]
Greg
Care to provide ISO/IEC 14882:2003 chapter and verse on that? Not
that I doubt what you assert, I would simply like to see how it's
actually stated in the Standard.
Can't you search your copy of the Standard for "covariant"?
I don't see the part about requiring the return type to be virtual.
"The return type of an overriding function shall be either identical to the
return type of the overridden function or covariant with the classes of the
functions. If a function D::f overrides a function B::f, the
return types of the functions are covariant if they satisfy the following
criteria:
? both are pointers to classes or references to classes98)
? the class in the return type of B::f is the same class as the class in the
return type of D::f, or is an
unambiguous and accessible direct or indirect base class of the class in
the return type of D::f
? both pointers or references have the same cv-qualification and the class
type in the return type of D::f
has the same cv-qualification as or less cv-qualification than the class
type in the return type of B::f.
If the return type of D::f differs from the return type of B::f, the class
type in the return type of D::f
shall be complete at the point of declaration of D::f or shall be the class
type D. When the overriding
function is called as the final overrider of the overridden function, its
result is converted to the type returned
by the (statically chosen) overridden function (5.2.2)."