A community for students.
Here's the question you clicked on:
 0 viewing

This Question is Closed

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0http://ideone.com/REaCY here it's printed twice!

asnaseer
 4 years ago
Best ResponseYou've already chosen the best response.1Looks 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
 4 years ago
Best ResponseYou've already chosen the best response.0right; taking away the delete gives me this: http://ideone.com/VHDOT

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0what if I make the balls static objects? I think it will work fine.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0now I get it... it's because I never call ball2's destructor in my original post (both ball1 and ball2 are dynamically allocated)

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0whereas in my last example ( http://ideone.com/JzRRO) as soon as main terminates their destructors are called.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0called automatically*

asnaseer
 4 years ago
Best ResponseYou've already chosen the best response.1the order in which static objects are deleted is not usually well defined. it also goes against the principals of good programming practices.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0right.... so how do I make sure, say, the static ball1 is deleted before the static ball2?

asnaseer
 4 years ago
Best ResponseYou've already chosen the best response.1delete ball1; delete ball2;

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0anyway... my example probably breaks 10 different C++ proper practices (using this in class methods, etc.)

asnaseer
 4 years ago
Best ResponseYou've already chosen the best response.1if 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
 4 years ago
Best ResponseYou've already chosen the best response.0I'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
 4 years ago
Best ResponseYou've already chosen the best response.0I only have the 4th edition though... so I'm sure there's probably something new that isn't covered :(

asnaseer
 4 years ago
Best ResponseYou've already chosen the best response.1ok  good. I guess you have to be shown the bad practices first in order to fully appreciate the good ones. :)

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0I might want to get this new book: http://www.amazon.com/Primer5thStanleyBLippman/dp/0321714113 which will release after half a year :P

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0http://ideone.com/oRc3z C++ is acting strange now :(
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.