011 # puzzle on c++/ OOPS

@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
• 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.
@dholey (1383)
• India
14 Oct 07
they are use for allocating memory also ... (refer to java)
@dholey (1383)
• India
19 Oct 09
i am back here after 3 years , and i find that the topics are still unanswered... hope to get correct answer ..... hope to meet more programmers here...
@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.
@dholey (1383)
• India
14 Oct 07
very good answer ... almost perfect .. but something is still missing find and give more light on it ... and then it will become the best responce .....
1 person likes this
@goodsign (2287)
• Malaysia
14 Oct 07
Thanks.