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
What is the cout in c++?
What language is a dll written in?
How does a C++ structure differ from a C++ class?
Define pre-condition and post-condition to a member function in c++?
what do you mean by volatile variable?
What is a c++ vector?
What is fixed in c++?
What is the latest version on c++?
Tell me difference between constant pointer and pointer to a constant.
How are pointers type-cast?
Write some differences between an external iterator and an internal iterator?
What is an associative container in c++?
How do we balance an AVL Tree in C++?
Define copy constructor.
What new()is different from malloc()?