By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,925 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,925 IT Pros & Developers. It's quick & easy.

multiple 'new' at single line

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a

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

P: n/a
"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.