如果我不指定对Base**的显式转换,为什么会出现编译错误?
当我处理派生类时,我能使用指向指针的指针吗?
class Base { };
class Child : public Base { };
void SomeFunction(Base** ppoObj) {}
void SomeFunction(Base* poObj) {}
int main()
{
Child *c = new Child();
// This passed.
SomeFunction(c);
SomeFunction((Base**)&c);
// CompilationError
SomeFunction(&c);
return 0;
}
Child1 *
强制转换为Child2 *
一样,即使它们是不相关的类型。只要您只分配与兼容类型的指针(即不要像我在示例中所做的那样),将Child **
转换为Base **
应该是可以的。 - Wyzard