Ok, I was reading through this entry in the FQA dealing about the issue of converting a Derived**
to a Base**
and why it is forbidden, and I got th
No, nasty_function()
isn't as nasty as it sounds. As the pointer b
points to something that is-a Base
, it's perfectly legal to assign a Base
-value to it.
Take care: your "Ooops" comment is not correct: d
still points to the same Derived
as before the call! Only, the Base
part of it was reassigned (by value!). If that gets your whole Derived
out of consistency, you need to redesign by making Base::operator=()
virtual. Then, in the nasty_function()
, in fact the Derived
assignment operator will be called (if defined).
So, I think, your example does not have that much to do with the pointer-to-pointer case.