covariant return types

Discussion in 'C++' started by Comp1597@yahoo.co.uk, Apr 11, 2009.

  1. Guest

    The following example of covariant return types is on the faq: I do
    feel that I understand this particular example.

    I would like to know the general conditions necessary and sufficient
    for covariant return types to work.
    I've googled a bit but haven't found a newbie-friendly account.

    Thanks.

    class Shape {
    public:
    virtual ~Shape() { } // A virtual destructor
    virtual void draw() = 0; // A pure virtual function
    virtual void move() = 0;
    ...
    virtual Shape* clone() const = 0; // Uses the copy constructor
    virtual Shape* create() const = 0; // Uses the default
    constructor
    };

    class Circle : public Shape {
    public:
    Circle* clone() const; // Covariant Return Types; see below
    Circle* create() const; // Covariant Return Types; see below
    ...
    };

    Circle* Circle::clone() const { return new Circle(*this); }
    Circle* Circle::create() const { return new Circle(); }
     
    , Apr 11, 2009
    #1
    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. Robert Elliot
    Replies:
    10
    Views:
    1,157
    Robert Elliot
    Jun 6, 2004
  2. Webb  Roberts

    Generics? Covariant return types?

    Webb Roberts, Nov 10, 2005, in forum: Java
    Replies:
    3
    Views:
    414
    Thomas Hawtin
    Nov 10, 2005
  3. Alex Vinokur
    Replies:
    7
    Views:
    516
    Karl Heinz Buchegger
    Apr 15, 2004
  4. Rob.
    Replies:
    9
    Views:
    404
    Alf P. Steinbach
    Jun 26, 2004
  5. Martin Stettner

    Covariant return types

    Martin Stettner, Jan 30, 2005, in forum: C++
    Replies:
    8
    Views:
    498
    Bogdan Sintoma
    Feb 1, 2005
Loading...

Share This Page