According the ARM, an overriding function in a derived class had to
have the same return type as the version in the base class.
This restriction has now been relaxed and the following is now legal:
The return type of an overriding function can be a pointer or reference to a class derived from the return type of the base class - a so-called covariant return type.
class Base
{
public:
virtual Base* clone();
};
class Derived : public Base
{
public:
Base* clone();
// not ideal return type
};
This restriction has now been relaxed and the following is now legal:
class Derived : public Base
{
public:
Derived* clone();
};
The return type of an overriding function can be a pointer or reference to a class derived from the return type of the base class - a so-called covariant return type.
class A
{
public:
virtual A* fetch();
};
class B : public A
{
public:
B* fetch();
};