Monday, 24 June 2013

Constructor


Question -- when we declare a variable Rational x;
    how does the compiler know how to construct it??
Answer --


The compiler provides a default constructor for both built-in types
and classes (user defined types)

If you do nothing, this default constructor will be called.  Sometimes that's OK, 
but usually you want to write your own constructor.

If you write any constructor, you do not get the default constructor.

A constructor is member function with the same name as the class.
It has no parameters and no return type --- not even VOID

No comments:

Post a Comment