Jason Sachs wrote:
In the function copy_info below, which happens first:
(a) X gets copied
(b) Y's destructor is called
class T
{
X m_info;
L m_semaphore;
public:
X copy_info();
}
X T::copy_info()
{
Y ylock(m_semaphore);
return m_info;
}
From what I can gather, creation of the temporary occurs as part of
executing the 'return' statement, and the destruction of 'ylock'
happens upon "exiting the scope", which is the next line after that,
which suggests that the temporary is created before 'ylock' is
destroyed.
>
and if Y's destructor happens first, is there any way to reverse the
order besides a brute force extra copy:
X T::copy_info()
{
Y ylock(m_semaphore);
X stupid_temporary(m_info);
return stupid_temporary;
}
'stupid_temporary' local object will be copied into a temporary
first (as part of the 'return' statement), then it will be destroyed.
Then 'ylock' will be destroyed.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask