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
Why do we use iterators?
What is class invariant in c++?
What is flush () in c++?
What is the full form of ios?
What do you understand by a pure virtual member function?
What is a list c++?
In c++, what is the difference between method overloading and method overriding?
What do you mean by storage classes?
What is & in c++ function?
What is algorithm in c++ programming?
Is it legal in c++ to overload operator++ so that it decrements a value in your class?
What are the advantages of c++?
Can malloc be used in c++?
What is the equivalent of Pascal's Real a) unsigned int b) float c) char
Where the memory to the static variables is allocated?