Topic: Covariance in return types.


Author: Darin Adler <darin@bentspoon.com>
Date: 1999/11/11
Raw View
Ivan Strougatski's original code was something like this (simplified a bit
to help the discussion):

    class ValueClass
    {
    public:
        int* getV();
    };

    class ListValueClass : public ValueClass
    {
    public:
        List<ValueClass>* getV();
    };

James Kuyper Jr. <kuyper@wizard.net> wrote:
> It isn't allowed. 10.3p5 requires that for covariant return types "both
> are pointers to classes or references to classes".

I think the above code is legal.

These getV() aren't virtual functions and the getV() in ListValueClass
doesn't override the getV() in ValueClass, although it does hide the getV()
inherited from ValueClass.

I don't think 10.3p5 applies here.

As I understand it, the getV() in ListValueClass can have any parameters and
any return value type the programmer wants, with no restrictions due to the
inherited getV() from ValueClass.

    -- Darin
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Ivan Strougatski <strougatski@clara.net>
Date: 1999/11/09
Raw View
I have a small hierarchy of classes part of which looks like this:

#define __underVal int

class ValueClass : public Statement
{
 public :
   .... // some stuff here
          __underVal* getV(){return val;}; // OVERLOADED EACH TIME !
          .....
 protected :
   __underVal* val; // OVERLOADED EACH TIME !

};

class ListValueClass : public ValueClass
{
 public :
    ... //some more stuff here
    List<ValueClass>* getV(){return val;};
    .. // some stuff here
 protected :
    List<ValueClass>* val;
};


While this is not a valid solution for various reasons, I am wondering
how could it be allowed providing that int is not a parent class, and
in fact is not class at all, to the List. (Note that this is not STL
List)
Compiler is Borland C++ Builder 4.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: 1999/11/10
Raw View
Ivan Strougatski wrote:
....
> While this is not a valid solution for various reasons, I am wondering
> how could it be allowed providing that int is not a parent class, and
> in fact is not class at all, to the List. (Note that this is not STL
> List)

It isn't allowed. 10.3p5 requires that for covariant return types "both
are pointers to classes or references to classes".


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]