Constructor overloading

 

Constructor overloading:

A class has two or more constructors with different function signatures.

Function signature means number of arguments or data type of arguments or both.

Ex:

#include<iostream.h>

class number

{

            privae:

                        int n;

            public:

                        number( )

                        {

                                    n=0;

                        }

                        number(int x)

                        {

                                    n=x;

                        }

                        void display( )

                        {

                                    cout<<n ;

                        }

};

void main( )

{

            number n1;

            number n2(10);

            n1.display( );

            n2.display( );

}

Comments