🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2070

Re: virtual overload differing in return type only?

#2070
From: John Barton
Date: Sat, 30 Sep 1995 13:10
49 lines
2116 bytes
In article <MATT.95Sep24001959@Austern>, clamage@Eng.Sun.COM (Steve Clamage) writes:
|>
|> 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.

  IBM's C++ compiler for AIX version 3.1.32 does not allow this
code to compile.  Just in case, I'll pass it along to the compiler
group as a possible bug.


--
John.

John J. Barton        jjb@watson.ibm.com            (914)784-6645
	<http://www.research.ibm.com/xw-SoftwareTechnology>
H1-C13 IBM Watson Research Center P.O. Box 704 Hawthorne NY 10598
---
[ 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: <44jcli$bas@watnews2.watson.ibm.com>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <43s5k2$nk6@gorby.mpd.tandem.com> <MATT.95Sep24001959@Austern>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 30 Sep 95 13:10:28 GMT
Approved: fjh@cs.mu.oz.au
From: jjb@watson.ibm.com (John Barton)
Newsgroups: comp.std.c++
Subject: Re: virtual overload differing in return type only?
X-Original-Date: 30 Sep 1995 12:20:02 GMT
Organization: IBM T.J. Watson Research Center
Message-ID: <44jcli$bas@watnews2.watson.ibm.com>
References: <43s5k2$nk6@gorby.mpd.tandem.com> <MATT.95Sep24001959@Austern>