473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

which comes first?

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;
}

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;
}

Feb 15 '07 #1
2 1410
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
Feb 15 '07 #2
On 15 Feb 2007 06:41:51 -0800, "Jason Sachs" <jm*****@gmail.comwrote:
>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;
}

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;
}
X gets copied, then Y's destructor is called.

-dr
Feb 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: KN | last post by:
I know both are pretty much the same and it comes down to personal choice. But I have to make the choice for the team. Things so far that I am considering 1. XML documentation in C# -- thats...
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
34
by: sushant | last post by:
hi all, suppose i have 2 loops one inside the other, like this 1) for(i=0;i<=100;i++) { for(j=0;j<=10;j++) { some code; }
2
by: hholidayy | last post by:
Hi everyone, I have a dilemma and I hope you could bring me some guidelines I want to develop some in-house software(s) at my work, to save everyone time and energy spent on the wrong repetitive...
7
by: Amadelle | last post by:
Hi all and thanks in advance, I am stuck! I can't figure out how to identify which button was clicked on my ASP.NET page in the PostBack event? So what I am trying to do is to is to have an if...
15
by: Brian Blais | last post by:
Hello, Are there any recommendations for which Windows python version to use? I'd like to see a pros-and-cons description of each, given that different uses might dictate different versions. ...
1
by: tlyczko | last post by:
I have Visual Studio Tools for Office (VSTO) and the SS 2005 Developer that comes with it, all of which I can install on my local XP box. 1. Which one do I install first, VSTO or SS 2005...
5
by: alingsjtu | last post by:
Hello, every body. When execute dynamic generated multiple OPENQUERY statements (which linkes to DB2) in SQLServer, I always got SQL1040N The maximum number of applications is already connected...
4
by: Mike | last post by:
Which comes first? The database schema or class design? I'm used to developing the database tables and fields based on the functional requirements of an application, so it makes sense to me to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.