http://ideone.com/zBPzc why was "Goodbye, World!" only printed once?

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

http://ideone.com/zBPzc why was "Goodbye, World!" only printed once?

Computer Science
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

http://ideone.com/REaCY here it's printed twice!
Looks like a race condition during program termination. In the first case, the program terminated before the output from the destructor of the class Ball had a chance to make it to the output stream.
right; taking away the delete gives me this: http://ideone.com/VHDOT

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

what if I make the balls static objects? I think it will work fine.
http://ideone.com/JzRRO
now I get it... it's because I never call ball2's destructor in my original post (both ball1 and ball2 are dynamically allocated)
whereas in my last example (http://ideone.com/JzRRO) as soon as main terminates their destructors are called.
called automatically*
the order in which static objects are deleted is not usually well defined. it also goes against the principals of good programming practices.
right.... so how do I make sure, say, the static ball1 is deleted before the static ball2?
delete ball1; delete ball2;
anyway... my example probably breaks 10 different C++ proper practices (using this in class methods, etc.)
if you are familiar with them, then you may want to consider using the shared pointers provided by the boost library to manage memory for you.
I'm still in like the first few chapters of my C++ primer book. I'm sure I will eventually learn about proper coding practices (RAII, etc)
I only have the 4th edition though... so I'm sure there's probably something new that isn't covered :(
ok - good. I guess you have to be shown the bad practices first in order to fully appreciate the good ones. :)
I might want to get this new book: http://www.amazon.com/Primer-5th-Stanley-B-Lippman/dp/0321714113 which will release after half a year :-P
http://ideone.com/oRc3z C++ is acting strange now :(

Not the answer you are looking for?

Search for more explanations.

Ask your own question