If I declare and object inside a for, and for example assign it’s adress to a pointer, when that for ends, would that pointer be pointing to invalid memory? Like it happens at the end of a method with the objects that you declared in that method
Share
Yes, and not just inside for – inside any block.
For example:
Same thing with
forexcept that the object will be created/destroyed each time the loop runs.Now, if instead you have:
And if you do that inside a for, you’ll need to be very careful not to leak all those allocations.