N
Nathan Phillips
In the following code at what point is the temporary object of class C
destroyed?
class C
{
public:
int i;
}
void foo(int & j);
foo(C().i);
What I am getting at is, is it possible that the memory referred to by j is
deallocated before foo is called?
I'm not so interested in what particular compilers do, though if you happen
to know for DJGPP then that would be useful, but whether the C++ standards
specify the behavior here. References would be appreciated if possible!
If you're interested, the particular code that raises this issue is where
class C is a smart pointer class returned by another function called within
the argument list of a function. i.e. foo(arg1, *getSmartPtr(), arg3). My
fear is that the destructor for the object pointed to may be called before
it is passed into foo.
Thanks in advance for any useful comments, Nathan
destroyed?
class C
{
public:
int i;
}
void foo(int & j);
foo(C().i);
What I am getting at is, is it possible that the memory referred to by j is
deallocated before foo is called?
I'm not so interested in what particular compilers do, though if you happen
to know for DJGPP then that would be useful, but whether the C++ standards
specify the behavior here. References would be appreciated if possible!
If you're interested, the particular code that raises this issue is where
class C is a smart pointer class returned by another function called within
the argument list of a function. i.e. foo(arg1, *getSmartPtr(), arg3). My
fear is that the destructor for the object pointed to may be called before
it is passed into foo.
Thanks in advance for any useful comments, Nathan