011 # puzzle on c++/ OOPS
By dholey
@dholey (1383)
India
October 14, 2007 6:51am CST
What is constructor ? what is the use of constructor? can we create constructor in protected / privet access area of class? if yes then how can we make objects of such class ???
common people answer it ... i will add comments on ur answers
2 responses
@spiderman05 (851)
• Canada
14 Oct 07
I prefer the word initializer to word constructor. Generally, these methods are meant to initialize the object's properties and not to allocate memory.
@goodsign (2287)
• Malaysia
14 Oct 07
Constructor is a special C++ class method (member function) which is automatically called when a class is first instantiated (when a class object is first created).
It is generally used to initialized the data members of the object.
Yes we can create constructor in protected or private access area of class.
In order to allow an external function to have access to the protected and private members of a class we have to declare the prototype of the external function that will gain access preceded by the keyword 'friend' within the class declaration that shares its members. As for example, declare the 'friend' function 'duplicate'.
Thanks.