Can Derived Class Contain Vector of pointers to the parent class?

Discussion in 'C++' started by ZhiYi, Jul 2, 2010.

  1. ZhiYi

    ZhiYi New Member

    Joined:
    Jul 2, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Lets say I have a parent class called:

    class Car
    {
    .....
    };

    Then there is a derived class called Toyota, which has a method returning a pointer to the parent class and a vector of pointers of the parent class.

    class Toyota : class Car
    {
    public:

    *Car GetCar(char* model);

    private:
    std::vector<Car*> cars;
    };

    Is this allowed?

    I came across this programming question which requests for a class and a derived class where the derived class has a container of pointers to the parent class and individual elements of the container has to be accessed quickly.
    (This question is neither a school assignment nor a test)

    :s11:
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice