class xyz{
...
...
};
while(i<n){
xyz ob;
...
...
}
Do I need to destroy the earlier object before reallocating memory to it?
No.
ob
is a stack-allocated object, so its own lifecycle is managed automatically. It's constructed at the place where you declare it, destructed at "}"
.while
iteration is the separate { ... }
scope, the object will be constructed and destructed each iteration.Nope, its scope is limited to the while loop.
No. The scope of ob
ends at the closing brace. The compiler automatically calls the destructor on stack-based objects when they go out of scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With