473,508 Members | 2,361 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)).coutCoco();
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 1288

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

Similar topics

1
2748
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...
2
2052
by: mantas44 | last post by:
Hello all, I have two tables tab_a id(int) tab_b id(int)
8
3679
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...
3
3314
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
1789
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...
2
1897
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...
2
1163
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...
1
1505
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...
10
1745
by: Anze | last post by:
Hmmm... anyone? :) Anze Anze wrote:
0
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
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...
1
5047
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...
0
4705
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...
0
3191
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1547
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 ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
414
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...

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.