K
kalki70
Hello,
I have a doubt about some behaviour. I couldn't find the answer
elsewhere, but maybe someone here knows.
If I have a function that receives an object as parameter :
void foo (SomeObject theObject);
And I call the function like this :
foo(SomeObject());
As the parameter is passed by value, not by reference, a copy of
"SomeObject" is generated and actually passed to the function foo. But
what happens with the original object?? When is it destroyed, after or
before the execution of foo() ?? Is that compiler dependent, or is
there some definition in the standard?
I tried an example using g++ compiler and the destructor of
"SomeObject" was called after the execution of function foo(), but I
want to know if I can rely on it as a standard behaviour.
Thanks for any help,
Luis
I have a doubt about some behaviour. I couldn't find the answer
elsewhere, but maybe someone here knows.
If I have a function that receives an object as parameter :
void foo (SomeObject theObject);
And I call the function like this :
foo(SomeObject());
As the parameter is passed by value, not by reference, a copy of
"SomeObject" is generated and actually passed to the function foo. But
what happens with the original object?? When is it destroyed, after or
before the execution of foo() ?? Is that compiler dependent, or is
there some definition in the standard?
I tried an example using g++ compiler and the destructor of
"SomeObject" was called after the execution of function foo(), but I
want to know if I can rely on it as a standard behaviour.
Thanks for any help,
Luis