Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: return types for virtual overriden functions

Reply
Thread Tools

Re: return types for virtual overriden functions

 
 
Makis Papapanagiotou
Guest
Posts: n/a
 
      07-31-2003
This is the rule actually

1.An overriding function in a derived class cannot be redefined to differ
only by its return type from a virtual function in a base class.

Hence it is illegal to differ only by the return type.

"venkat" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> Why is this not allowed as against using reference types for return?
>
> class A{
> public:
> virtual A fun(){
> }
>
> };
>
> class B ublic A{
> public:
> B fun(){
> }
> };



 
Reply With Quote
 
 
 
 
Gavin Deane
Guest
Posts: n/a
 
      07-31-2003
"Makis Papapanagiotou" <(E-Mail Removed)> wrote in message news:<bgaokb$nvq$(E-Mail Removed)>...

<top posting rearranged>

> "venkat" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) m...
> > Why is this not allowed as against using reference types for return?
> >
> > class A{
> > public:
> > virtual A fun(){
> > }
> >
> > };
> >
> > class B ublic A{
> > public:
> > B fun(){
> > }
> > };

> This is the rule actually
>
> 1.An overriding function in a derived class cannot be redefined to differ
> only by its return type from a virtual function in a base class.
>
> Hence it is illegal to differ only by the return type.


Where is that rule from? If the OP had had A::fun returning an A& and
B::fun returning a B& that would not be illegal. The question as I
read it is why is it legal with references but not with objects
themselves. Apart from the not very helpful "because the standard says
so" answer, I don't really know.

GJD
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-31-2003
"Gavin Deane" <(E-Mail Removed)> wrote...
> [...]
> Where is that rule from? If the OP had had A::fun returning an A& and
> B::fun returning a B& that would not be illegal. The question as I
> read it is why is it legal with references but not with objects
> themselves. Apart from the not very helpful "because the standard says
> so" answer, I don't really know.


You should probably ask in comp.std.c++, then. That's where the
rationale behind many language constructs is discussed. Here, in
comp.lang.c++, we talk "how". There, in comp.std.c++, they talk
"why".

Victor


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to determine if virtual function in base class is overriden? noel.hunt@gmail.com C++ 6 12-20-2006 09:10 AM
private virtual functions and pure virtual functions with bodies John Goche C++ 10 12-08-2006 04:00 PM
polymorphic return types in virtual functions Aryeh M. Friedman C++ 2 02-21-2005 01:53 PM
Boost + Python C/API: Mixing python return types with boost return types Steve Knight Python 2 10-10-2003 10:11 AM
Re: return types for virtual overriden functions Howard C++ 2 07-31-2003 03:03 PM



Advertisments