anonymous
  • anonymous
http://ideone.com/zBPzc why was "Goodbye, World!" only printed once?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
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.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
http://ideone.com/REaCY here it's printed twice!
asnaseer
  • asnaseer
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.
anonymous
  • anonymous
right; taking away the delete gives me this: http://ideone.com/VHDOT

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
what if I make the balls static objects? I think it will work fine.
anonymous
  • anonymous
http://ideone.com/JzRRO
anonymous
  • anonymous
now I get it... it's because I never call ball2's destructor in my original post (both ball1 and ball2 are dynamically allocated)
anonymous
  • anonymous
whereas in my last example (http://ideone.com/JzRRO) as soon as main terminates their destructors are called.
anonymous
  • anonymous
called automatically*
asnaseer
  • asnaseer
the order in which static objects are deleted is not usually well defined. it also goes against the principals of good programming practices.
anonymous
  • anonymous
right.... so how do I make sure, say, the static ball1 is deleted before the static ball2?
asnaseer
  • asnaseer
delete ball1; delete ball2;
anonymous
  • anonymous
anyway... my example probably breaks 10 different C++ proper practices (using this in class methods, etc.)
asnaseer
  • asnaseer
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.
anonymous
  • anonymous
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)
anonymous
  • anonymous
I only have the 4th edition though... so I'm sure there's probably something new that isn't covered :(
asnaseer
  • asnaseer
ok - good. I guess you have to be shown the bad practices first in order to fully appreciate the good ones. :)
anonymous
  • anonymous
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
anonymous
  • anonymous
http://ideone.com/oRc3z C++ is acting strange now :(

Looking for something else?

Not the answer you are looking for? Search for more explanations.