Topic: virtual overload differing in return type only?


Author: jhg@mpd.tandem.com (Jim Garrison)
Date: 1995/09/27
Raw View
In <MATT.95Sep24001959@Austern>, clamage@Eng.Sun.COM (Steve Clamage) writes:
>
>jhg@mpd.tandem.com (Jim Garrison) writes:
>

[snip]

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

Thanks for the reply.  The example I gave was incorrect, and what
I WAS looking for was 'covariant return types'.  This change (not
yet implemented in SGI's compiler) allows me to do exactly what I
want.

Jim Garrison
jhg@acm.org


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





Author: jjb@watson.ibm.com (John Barton)
Date: 1995/09/30
Raw View
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. ]





Author: jhg@mpd.tandem.com (Jim Garrison)
Date: 1995/09/23
Raw View
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.

Jim Garrison
jhg@acm.org
---
[ 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. ]





Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/09/24
Raw View
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. ]