In C++, do derived classes need its own constructors defined if it only requires constructors from the base class?

Viewed 17

Suppose the base class has three constructors, one without parameter and one with parameters, and a copy constructor, as follows:

class Base {
  public:
    Base();    //default constructor
    Base(unsigned int width, unsigned int height);    //parametrized constructor
    Base(Base const & other);    //copy constructor
  private:
    int width_;
    int height_;  
}

Suppose a derived class is like this:

class Derived : public Base {
public:
  Derived();    //is this even needed?
  Derived(int width, int height);   //is this even needed?
  Derived(Derived const & other);   //is this even needed?
private:
  void additionalFunction(); //additional functionality not in base class
}

Is it even needed to declare (and define) the constructors for the derived class if it only require the base class's constructors? In another word, do I need to define the derived class constructors like this:

Derived::Derived(){
    Base();
}

And if so, is this the correct way to define the copy constructor:

 Derived::Derived(Base const & other){
     Base(other);
 }

Thanks

0 Answers
Related