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
The blog provides study material for Computer Science(CS) aspirants. Mostly says "material nahi milta, padhun kahan se.", I think If you can not find content on the Internet, then you are not a CS student. Dedicated to (Prof. Rakesh Kumar, DCSA, K.U.Kurukshetra, HARYANA, INDIA)- "Ek teacher ka bahut jyada padhna, bahut jyada jaroori hota hai."
Monday, 24 June 2013
Constructor
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment