C++ Constructor Initialize default value in constructor Initialization list

Description

C++ Constructor Initialize default value in constructor Initialization list

#include <iostream>

using namespace std;

class Shape/*from  www  . ja  v a  2  s.  c om*/
{
public:
    int side;
    Shape(int s) : side(s) {}
};

class Rectangle : public Shape
{
protected:
    int height;
    int width;
public:
    Rectangle(int Records, int s) : Shape(s),
        height(1), width(Records) {}

    Rectangle(int Records) : Shape(8675309),
        height(1), width(Records)  {}
};

int main()
{
    Rectangle CD(20, 5551212);
    Rectangle OldCD(30);
    cout << CD.side << endl;
    cout << OldCD.side << endl;
}



PreviousNext

Related