Uh right, the destructor of an object is called when it goes out of scope.
Most likely you're passing the object by value as a parameter to Update. A new object is created at entry of the function, and is thus destructed when the function ends:
#include <iostream>struct Object{ int x; Object(){ std::cout << "Made 1 object.\n"; ~Object(){ std::cout << x << " dies!\n"; }};void Update(Object foo){ // stuff!}int main(){ Object *bar=new Object(); bar->x=42; Update(*bar); delete bar;}
So what should this code do?
Made 1 object.42 dies!42 dies!
The copy's destructor is called at the end of Update(), thus creating the perhaps unexpected duplication of death messages.