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
Difference between a copy constructor and an assignment operator.
What is #include sstream?
Is it possible to provide special behavior for one instance of a template but not for other instances?
What are iterators in c++?
What is a lambda function c++?
How do I use arrays in c++?
What is the use of :: operator in c++?
Can you please explain the difference between overloading and overriding?
what are the events occur in intr activated on interrupt vector table
What is the use of string in c++?
When to use “const” reference arguments in a function?
Why c++ is the best language?
Why is the function main() special?
Explain the concept of copy constructor?
What is c++ manipulator?