Thread View: comp.std.c++
4 messages
4 total messages
Started by Jim Garrison
Sat, 23 Sep 1995 16:02
virtual overload differing in return type only?
Author: Jim Garrison
Date: Sat, 23 Sep 1995 16:02
Date: Sat, 23 Sep 1995 16:02
25 lines
1132 bytes
1132 bytes
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. ]
Re: virtual overload differing in return type only?
Author: 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. ]
Re: virtual overload differing in return type only?
Author: Jim Garrison
Date: Wed, 27 Sep 1995 18:22
Date: Wed, 27 Sep 1995 18:22
30 lines
1375 bytes
1375 bytes
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. ]
Re: virtual overload differing in return type only?
Author: John Barton
Date: Sat, 30 Sep 1995 13:10
Date: Sat, 30 Sep 1995 13:10
49 lines
2116 bytes
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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads