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
Explain what are single and multiple inheritances in c++?
What is static function? Explain with an example
What is a Default constructor?
what are the iterator and generic algorithms.
Why is c++ so fast?
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
what is a class? Explain with an example.
What is a loop? What are different types of loops in c++?
What is the difference between method overloading and method overriding in c++?
write a corrected statement so that the instruction will work properly. if (4 < x < 11) y = 2 * x;
How would you find out if a linked-list is a cycle or not?
What is #include iostream in c++?
What is a hashmap c++?
If dog is a friend of boy, and terrier derives from dog, is terrier a friend of boy?
What is oop in c++?