This is the mail archive of the
mailing list for the GCC project.
Re: gcc-4.0-virtual function return type
- From: "Giovanni Bajo" <giovannibajo at libero dot it>
- To: "JFanatiker" <jfanatiker at yahoo dot de>
- Cc: <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 7 Nov 2004 22:05:47 +0100
- Subject: Re: gcc-4.0-virtual function return type
- References: <firstname.lastname@example.org>
> Why are you going to throw away such good features like this one?
> This feature is something greatly extending the object oriented
> programming. - A method of a derived class can return a more
> specialised type as its parent- thats what oop is all about!:
> Specialisation of a base class. (This greatly extends polymorphism-
> very, very usefull!)
ISO C++ allows covariant return types, so you still can change the return type
using covariance: if you have a function returning B*, you can override it with
a function returning D*, assuming D is derived from B. The extension in GCC was
relaxing this rule so that you could do that for any D which is implicitally
convertible to B. This allowed for instance B*=void*, D*=any builtin type.
Anyway, I must say that the paragraph in changes.html is a little too complex
for an average C++ user. An example would help.