After reading this question, i saw the answer by Naveen containing a link to this page, which basically says, that casting from Derived** to Base** is forbidden since could change a pointer to an pointer to a Derived1 object point to a pointer to a Derived2 object (like: *derived1PtrPtr=derived2Ptr).
OK, i understand this is evil …
But when casting Derived** to Base*const* this is not even possible, so whats the reason that this is not allowed anyway ?
First thing is that, if you really need to, you can cast any pointer type to any other pointer type. For instance, you can cast to
void*as an intermediate step.Second, with pointers-to-pointers, it’s not so much that there’s a reason to make particular cases hard as that there are no special rules to make any particular cases easy.
Basically, you have a pointer to
X– whereXin your case happens to be another pointer. SomeXcases get special treatment (e.g. derived classes can implicitly cast to bases) – but yourXis not one of them. It’s not the base class – it’s a pointer. There are no implicit casts defined forderived**, other than tovoid*– you can’t even implicitly castderived**tovoid**.I don’t think the
consthas much to do with it in this case, though I could be missing something.