Isn't the constructor inherited by derived classes ??
Not in the way you're thinking, no.
You have to give rectangle and triangle a constructor that takes parameters, then explicitly call the parent constructor:
1 2 3 4 5 6 7 8 9
class rectangle : public polygon
{
public:
rectangle(int a, int b) // <- give rectangle a constructor
: polygon( a, b ) // <- have it call its parent's constructor
{
}
//...
No, they don't, in sense of using it as their constructor. Derived classes do inherit constructors, but they use them only to construct base class part of itself. If isn't specified otherwise (which I did in my snippet) derived class constructors will use default base class constructor.
Default constructor and copy constructor are created by compiler if not specified. In your code compiler-reated default constructor of derived class called, which calls default constructor of base class. Which defined as default i.e. compiler generated.
@MiiNiPaa
No, they don't, in sense of using it as their constructor.
I never said that base class constructors are used as constructors of derived classes. And nobody here said that. So it is only your fantasies you are trying to argue with yourself.:)
@MiiNiPaa
In your code compiler-reated default constructor of derived class called, which calls default constructor of base class. Which defined as default i.e. compiler generated.
In my example the derived class constructor calls protected member of the base class. If it would not be inherited the derived class could not call it.:)
By the way the same way the base class copy assignment operator also is inherited by a derived class. For example