user27279
user27279

Reputation: 155

C++ Inheritance - QList

I have a class, Car, that inherits a QList< int >. I am wondering how would I use the QList I just inherited?

From my amateur understanding of how to use inheritance, if Car inherits Vehicle, I would access a method of Vehicle by going Vehicle::getWheels(). How would this work if I inherit QList though?

Upvotes: 0

Views: 1538

Answers (1)

hochl
hochl

Reputation: 12920

If your Car inherits from Vehicle you can simply use the inherited methods (in case you have not overwritten those). Example:

class Vehicle
{
    int wheels_;

    public:
        Vehicle(int wheels=4)
        : wheels_(wheels)
        {
        }

        int getWheels() const { return wheels_; }
};

class Car: public Vehicle
{
};

Car myCar;
myCar.getWheels();

So for your question, you can simply use the members of QList< int > without being explicit if your class was decleared as class Car : public QList< int > { ... };.

Upvotes: 1

Related Questions