Re: return types for virtual overriden functions

Discussion in 'C++' started by Makis Papapanagiotou, Jul 31, 2003.

  1. 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" <> wrote in message
    news:...
    > Why is this not allowed as against using reference types for return?
    >
    > class A{
    > public:
    > virtual A fun(){
    > }
    >
    > };
    >
    > class B :public A{
    > public:
    > B fun(){
    > }
    > };
     
    Makis Papapanagiotou, Jul 31, 2003
    #1
    1. Advertising

  2. Makis Papapanagiotou

    Gavin Deane Guest

    "Makis Papapanagiotou" <> wrote in message news:<bgaokb$nvq$>...

    <top posting rearranged>

    > "venkat" <> wrote in message
    > news:...
    > > Why is this not allowed as against using reference types for return?
    > >
    > > class A{
    > > public:
    > > virtual A fun(){
    > > }
    > >
    > > };
    > >
    > > class B :public 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
     
    Gavin Deane, Jul 31, 2003
    #2
    1. Advertising

  3. "Gavin Deane" <> 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
     
    Victor Bazarov, Jul 31, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Howard
    Replies:
    2
    Views:
    390
    Karl Heinz Buchegger
    Jul 31, 2003
  2. Aryeh M. Friedman
    Replies:
    2
    Views:
    1,118
    Ron Natalie
    Feb 21, 2005
  3. Steve Knight
    Replies:
    2
    Views:
    780
    Steve Knight
    Oct 10, 2003
  4. John Goche
    Replies:
    10
    Views:
    772
    Marcus Kwok
    Dec 8, 2006
  5. Replies:
    6
    Views:
    450
    Alf P. Steinbach
    Dec 20, 2006
Loading...

Share This Page