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
Discuss the possibilities related to the termination of a program before entering the mainq method?
Why is polymorphism useful?
What is operator overloading in c++ example?
What is the meaning of string in c++?
Define a pointer to a data member of the type pointer to pointer?
How do we balance an AVL Tree in C++?
What is the rule of three?
Can you declare an array without a size in c++?
How does list r; differs from list r();?
How do you master coding?
When is the copy constructor called?
What are vectors used for in c++?
How can a called function determine the number of arguments that have been passed to it?
What is a far pointer? where we use it?
Is oops and c++ same?