Passing objects—compiler dependency

When you pass an object to a function by value, the C++ compiler creates a temporary copy of the object to pass to the function. The compiler deletes the object after the function returns. The exact time at which temporary objects are deleted is compiler-dependent. For this reason, your application must not rely on the automatic destruction of temporary objects.

For example, if you pass an ITConnection object to a function by value and start the AddCallback method on the connection inside the function, the temporary connection object (on which you added the callback) might or might not exist immediately after the function returns. Because both the original connection object and the copy refer to the same underlying server connection, the new callback might or might not remain in effect on the underlying connection when your function returns.

To ensure consistent behavior, call DelCallback inside your function when the new callback is no longer required. Do not rely on the automatic destruction of the connection object parameter by the compiler to remove the callback from the underlying server connection. For details about DelCallback, see The ITErrorManager class.