In a class, there is a reference or pointer of an object of
another class embedded, and the memory is either allocated
or assigned to the new object created for this class. In
the constructor, parameters are passed to initialize the
data members and the embedded object reference to get
inialized. What measures or design change should be advised
for proper destruction and avioding memory leaks, getting
pointers dangling for the embedded object memory
allocation? Please suggest.

Answer Posted / som shekhar

If you are using the reference orpointer of other class as
an Aggregation (class own every thing, tight coupling) then
the destructor should take care of it, but if the reference
or pointer is taken as composition (class doesnt owwn the
pointer, loose coupling) then the class destructor should
not worry about that.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what are single and multiple inheritances in c++?

636


What is static function? Explain with an example

675


What is a Default constructor?

1067


what are the iterator and generic algorithms.

1560


Why is c++ so fast?

624






Will a recursive function without an end condition every quit, in practice a) Compiler-Specific (Some can convert to an infinite loop) b) No c) Yes

696


what is a class? Explain with an example.

753


What is a loop? What are different types of loops in c++?

691


What is the difference between method overloading and method overriding in c++?

647


write a corrected statement so that the instruction will work properly. if (4 < x < 11) y = 2 * x;

1611


How would you find out if a linked-list is a cycle or not?

642


What is #include iostream in c++?

674


What is a hashmap c++?

652


If dog is a friend of boy, and terrier derives from dog, is terrier a friend of boy?

708


What is oop in c++?

688