Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Why the standard doesn't force following the "simple" references link ?

Reply
Thread Tools

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

 
 
X Ryl
Guest
Posts: n/a
 
      04-21-2006
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nike air force one, air force 1, air force one low cut, air force one abdul_razak@indiatimes.com Digital Photography 2 12-31-2008 04:29 PM
Nike Air Force Ones,Air Force One Air Force One-1 lky52193@gmail.com Computer Support 0 01-17-2008 04:40 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:46 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:34 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM



Advertisments