pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)
[personal profile] pne

Don't copy pointers to child objects (has-a relationship) in your operator =; sharing common children this way will bite you when you try to destroy your child objects and they've already been destroyed.

Fortunately, the STL implementation we use replaces internal pointers with "magic" nonsense values after the object is destroyed so you at least get a segfault and notice.

Date: Monday, 27 October 2003 06:48 (UTC)
From: [identity profile] crschmidt.livejournal.com
"If you're lucky, you get a segfault.

If you're unlucky, you're just screwed."

Jason Zych, Data Structures in C++, UIUC 2003.

Date: Monday, 27 October 2003 06:52 (UTC)
ext_78: A picture of a plush animal. It looks a bit like a cross between a duck and a platypus. (Default)
From: [identity profile] pne.livejournal.com
Very true. Especially the bit about segfaulting being the lucky case.

have you consider smart pointers?

Date: Monday, 27 October 2003 08:37 (UTC)
From: [identity profile] signal11.livejournal.com
I use them fairly extensively for code I write at work. It's designed (to me a least!) for these sort of problems.

The implementation I use at work is not available publicly but I've heard these are pretty good:
http://www.boost.org/libs/smart_ptr/index.htm

Date: Monday, 27 October 2003 11:26 (UTC)
From: [identity profile] timwi.livejournal.com
The joys of implicit sharing, as done fantastically in Qt :-)

Profile

pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)
Philip Newton

June 2015

S M T W T F S
 12 3456
78910111213
14151617181920
2122232425 2627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Thursday, 1 January 2026 14:14
Powered by Dreamwidth Studios