473,666 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why the standard doesn't force following the "simple" references link ?

For example, let's say I have such classes :
struct G
{
int value;
G(int a) : value(a) {}
~G() { cout<< value <<" - G is Destructed!!!"< <endl; value = 0; }
};

struct B
{
G a1;
virtual ~B() { cout<<"B is Destructed!!!"< <endl; }
B(G a) : a1(a) {}
};

struct C : public B
{
G a2;
C(G a, G b) : B(a), a2(b) {}
virtual ~C() { cout<<"C is Destructed!!!"< <endl; }
};

struct A
{
const B & ref;
A & coutCoco() { cout << "Coco" << endl; return *this;}

A(const B& _ref) : ref(_ref) {}
};

and in the code I simply does this :
A a(C(3, 2));

// Use a...
cout<<"End was here"<<endl;

For what I understand from the standard, the output should be:
G is destructed (this one is for the temporary "3" or "2" because
argument are evaluated at compiler choice)
G is destructed (this one is for the other temporary)
C is destructed (this is for the C temporary)
G is destructed (for the local C's a2 member)
B is destructed (again for the temporary C)
G is destructed (for local B's a1 member)
End was here

However, in such an easy example, the temporary C object is no more
reachable after the "a" definition, so the "ref" member of "a" refers
to a destructed object.
Why doesn't the standard force the temporary C object to live until "a"
is destructed, in such an "easy" to spot case ?

BTW, the standard ensure that if I had called the stuff like:
A y = A(C(3,2)).coutC oco();
the temporaries A, C are still reachable(not destructed) when using the
coutCoco method. y's "ref" is not however reachable after that line.

Apr 21 '06 #1
0 1296

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

Similar topics

1
2754
by: Richard | last post by:
http://dynamicdrive.com/dynamicindex1/switchmenu.htm I want to add a second level menu item to the existing design. Currently only one level is possible. Item 1 ......link ......link item 2 item 3
2
2061
by: mantas44 | last post by:
Hello all, I have two tables tab_a id(int) tab_b id(int)
8
3687
by: Beam_Us_Up_Scotty | last post by:
Hello all, I am trying to write a "simple" animation using C#, and I've tried many things but nothing seems to work for me without leaking memory. Here's a very simple piece of code that uses a timer to set the image of a label from an ImageList every 100ms or so. This is what was being used when I inherited this piece of code, and I thought it was OK, until I changed the size of the label to do animation on a larger piece of screen...
3
3325
by: BKDotCom | last post by:
This has surely been answered somewhere multiple times, but... I'm guessing it's some sort of "bubbling" thing.... <STYLE> ..triggerarea { border:#00C solid 1px; } </STYLE> <UL ID="menu">
4
1797
by: bugbear | last post by:
Hello; I have (tried) to change my geocities site to be "styled" not "tabled". It's certainly made the HTML nicer. But it doesn't work as nicely I'd like. And it almost doesn't work at all under IE.
2
1904
by: Phillip Vong | last post by:
I know how to check IsPostback, but what is the VB code to force a postback? I have a link I want to do a postback with this URL. I've tried using Postback and I've tried using doPostback. Am I missing something? I just want the link to postback to this site. "~/Misc/Forms.aspx?InsertMode=Yes"
2
1168
by: Martin Arvidsson, Visual Systems AB | last post by:
Hi! I need help with a solution. I want a System.Timers.Timer to timeout everyday at 09:00. I store the time in a string in a config file. When the service is executed i stop the timer and execute the work. After execution, i want to set the timer to be executed at 09.00 again.
1
1510
by: Luis Freitas | last post by:
I have a table with the following Fields: Article and 8 fields that are Dates. Under each date is a quantity. I would like to run a query that would have only 3 columns: Article, Date and Quantity Thank you very much
10
1759
by: Anze | last post by:
Hmmm... anyone? :) Anze Anze wrote:
0
8443
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8866
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6192
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.