This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: egcs-1.1 and the C++ standard
- To: ak at muc dot de (Andi Kleen)
- Subject: Re: egcs-1.1 and the C++ standard
- From: Joe Buck <jbuck at synopsys dot com>
- Date: Sat, 20 Jun 98 10:23:59 PDT
- Cc: jason at cygnus dot com, jbuck at synopsys dot com, egcs at cygnus dot com
> > Non-trivial covariant returns
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> Could you expand on this one? Does this mean that the Standard somehow
> supports overloading based on return types now?
He's talking about the feature that allows you to override a virtual
function that returns a pointer or reference to B by one that returns a
pointer or reference to D, where D is derived from B. It's useful for
things like clone methods (sometimes called the "virtual copy constructor"
pattern):
class B {
public:
...
B* clone() const { return new B(*this);}
};
In the ARM days you'd have to write
class D : public B {
public:
...
B* clone() const { return new D(*this);}
};
and probably wind up doing downcasts in your code.
Now you can write
...
D* clone() const { return new D(*this);}
The idea is that the return value from clone will always match the static
type of the pointer or reference you call it on.
For single inheritance, this is pretty simple to implement; the
code comes out the same. For multiple inheritance or virtual
base classes, there's more work (adding an offset, etc).