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

Why do we use iterators?

864


What is class invariant in c++?

993


What is flush () in c++?

841


What is the full form of ios?

792


What do you understand by a pure virtual member function?

795


What is a list c++?

887


In c++, what is the difference between method overloading and method overriding?

855


What do you mean by storage classes?

1195


What is & in c++ function?

826


What is algorithm in c++ programming?

826


Is it legal in c++ to overload operator++ so that it decrements a value in your class?

855


What are the advantages of c++?

1378


Can malloc be used in c++?

840


What is the equivalent of Pascal's Real a) unsigned int b) float c) char

816


Where the memory to the static variables is allocated?

818