Passing arguments to a superclass constructor

前端 未结 2 619
一整个雨季
一整个雨季 2021-01-22 02:04

I\'m just getting into derived classes, and I\'m working on the famous Shape class. Shape is the base class, then I have three derived classes: C

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-22 02:41

    Almost. Instead of redeclaring the parameters here:

    Rectangle(double w, double h) : Shape(double w, double h)
    

    You should simply "pass them through" (to give an inexact phrasing):

    Rectangle(double w, double h) : Shape(w, h)
    { }
    

提交回复
热议问题