<p>Am 14.10.2014 12:41 schrieb "Marco van de Voort" <<a href="mailto:marcov@stack.nl">marcov@stack.nl</a>>:<br>
><br>
><br>
> I recently had to dive a bit into C++ again, and reconnected with a feature<br>
> I liked at first sight, the C++ covariance of virtual methods (changing the<br>
> return type of a overriden method to a descendant of the original type).<br>
> Googling a bit it seems that some languages(C#) also seem to allow this for<br>
> parameters.  (not just return types)<br>
><br>
> I suddenly wondered why it was never proposed or talked about  for FPC,<br>
> since it seems such a nice feature.  Is there something particularly wrong<br>
> with it?</p>
<p>At least at first sight there don't seem to be any real (technical) reasons to not covariance for return values. Parameters would be a different topic though...</p>
<p>Just so I get the idea right: </p>
<p>=== code begin ===</p>
<p>type<br>
  TBar = class<br>
    function Test: TObject; virtual;<br>
  end;</p>
<p>  TFooBar = class(TBar)<br>
    function Test: TStrings; override;<br>
  end;</p>
<p>//...</p>
<p>var<br>
  b: TBar;<br>
  f: TFooBar;<br>
  s: TStrings;<br>
begin<br>
  f := TFooBar.Create;<br>
  b := f;<br>
  // this would work<br>
  s := f.Test;<br>
  // but this not<br>
  s := b.Test;<br>
end.</p>
<p>=== code end ===</p>
<p>Would this be the correct equivalent in Object Pascal?</p>
<p>Regards,<br>
Sven</p>