472,102 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

multiple 'new' at single line

Hi, people.

Can anybody explain me "multiple 'new' at single line"
behavior. Consider:

p::p(void*);
p::p(void*,void*);

new A( p(new B), p( new C(p(new D), p(new E)) ), p(new F));

Will it be either

1.
new F p(*)
new E p(*)
new D p(*)
new C p(*)
new B p(*)
new A

and
2.
new B p(*)
new D p(*)
new E p(*)
new C p(*)
new F p(*)
new A p(*)

or
3.

new E
new D
new F
new C
new B
p(*)
p(*)
p(*)
p(*)
p(*)
new A

Does C++ guarantee that never can be like upper
case 3 (more than one "new" befor "p(*)").

Do we need to create temp storages:

const p tmp1(new F);
const p tmp2(new E);
const p tmp3(new D);
const p tmp4(new C(tmp3,tmp2));
const p tmp5(new B);
new A(tmp5,tmp4,tmp1);

Jan 1 '07 #1
3 1747
"Grizlyk" <gr******@yandex.ruwrote:
Hi, people.

Can anybody explain me "multiple 'new' at single line"
behavior. Consider:

p::p(void*);
p::p(void*,void*);

new A( p(new B), p( new C(p(new D), p(new E)) ), p(new F));
The only order guarantee you have with the above is that the B, D, E and
F object will be created first (in any order); that C will be created
after D and E; and that B through F will all be created before A.
Outside of that, there are no order guarantees.
Jan 2 '07 #2

Daniel T. wrote:
new A( p(new B), p( new C(p(new D), p(new E)) ), p(new F));

The only order guarantee you have with the above is that the B, D, E and
F object will be created first (in any order); that C will be created
after D and E; and that B through F will all be created before A.
Outside of that, there are no order guarantees.
I do not understand, can be optimized or no like this:

compiled_tmp1=new D,
compiled_tmp2=new E,
compiled_p1=p(compiled_tmp1),
compiled_p2=p(compiled_tmp2),
new c(compiled_p1, compiled_p2);

Jan 2 '07 #3
"Grizlyk" <gr******@yandex.ruwrote:
Daniel T. wrote:
new A( p(new B), p( new C(p(new D), p(new E)) ), p(new F));
The only order guarantee you have with the above is that the B, D, E and
F object will be created first (in any order); that C will be created
after D and E; and that B through F will all be created before A.
Outside of that, there are no order guarantees.

I do not understand, can be optimized or no like this:

compiled_tmp1=new D,
compiled_tmp2=new E,
compiled_p1=p(compiled_tmp1),
compiled_p2=p(compiled_tmp2),
new c(compiled_p1, compiled_p2);
Yes, it can be done like that. It can also be done like this:

compiled_tmp1=new D,
compiled_p1=p(compiled_tmp1),
compiled_tmp2=new E,
compiled_p2=p(compiled_tmp2),
new c(compiled_p1, compiled_p2);

or like this:

compiled_tmp2=new E,
compiled_p2=p(compiled_tmp2),
compiled_tmp1=new D,
compiled_p1=p(compiled_tmp1),
new c(compiled_p1, compiled_p2);

or like this:

compiled_tmp2=new E,
compiled_tmp1=new D,
compiled_p1=p(compiled_tmp1),
compiled_p2=p(compiled_tmp2),
new c(compiled_p1, compiled_p2);

Or any of a few other orders I expect.
Jan 2 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Matthew Louden | last post: by
32 posts views Thread by tshad | last post: by
4 posts views Thread by Neo Geshel | last post: by
9 posts views Thread by Graham | last post: by
6 posts views Thread by Bill | last post: by
47 posts views Thread by Mark | last post: by
reply views Thread by Grizlyk | last post: by

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.