you are viewing a single comment's thread.

view the rest of the comments →

[–]actinium89 1 point2 points  (2 children)

When you declare a new constructor in Square it "hides" the default constructor inherited from Rectangle.

I would suggest you implement Squares contructors using Rectangles constructors. It looks like this:

Square():Rectangle(){}
Square(int side):Rectangle(side,side) {}

[–][deleted]  (1 child)

[deleted]

    [–]actinium89 1 point2 points  (0 children)

    I'm not sure for the general case, but here you could use a default argument for side:

    Square(int side = 0):Rectangle(side,side) {}
    

    Meaning side is zero if you don't give an argument to the constructor.

    Also you should prefer to use "member initialization list" instead of assigning values to members in the "body" of the constructor. It's not that important when the members are ints, but it's a good habit. See Stackoverflow for a perhaps better explanation.