Article View: comp.std.c++
Article #2019Re: virtual overload differing in return type only?
From: Steve Clamage
Date: Sun, 24 Sep 1995 08:19
Date: Sun, 24 Sep 1995 08:19
40 lines
1642 bytes
1642 bytes
jhg@mpd.tandem.com (Jim Garrison) writes:
>The ARM states that it is illegal to declare a function in a
>derived class that differs from a virtual in a parent class by
>only its return type. I.e.
>class A
>{
> virtual int foo();
>}
>class B1 : public A
>{
> char * foo(); // Illegal
>}
>Has the standard changed with respect to this? IBM VisualAge C++
>now allows this (it's an EXTREMELY useful thing to be able to do),
>but the SGI compiler on which I'm working doesn't.
The draft standard allows "covariant return types".
If the base-class version of a virtual function returns a
pointer (or reference) to a class, the derived-class version may
return a pointer (or reference) to a class derived from the
original.
Your example above is not allowed, because char* is not derived
from int. If the IBM compiler allows it, that would be a
non-standard extension.
--
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<MATT.95Sep24001959@Austern>Path:
arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!MattReferences:
<43s5k2$nk6@gorby.mpd.tandem.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: virtual overload differing in return type only? Date: 24 Sep 1995 08:19:59 GMT Organization: Sun Microsystems Inc., Mountain View, CA Approved: matt@austern.HIP.berkeley.edu Message-ID: <MATT.95Sep24001959@Austern> References: <43s5k2$nk6@gorby.mpd.tandem.com> NNTP-Posting-Host: austern.hip.berkeley.edu