This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc-4.0-virtual function return type


JFanatiker wrote:

> 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.

Giovanni Bajo



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]