我有一个代码片段如下:
class ClassA
{
public:
virtual ~ ClassA() {};
virtual void FunctionA() {cout << "ClassA" << endl;}
};
class ClassB
{
public:
virtual void FunctionB() {};
};
class ClassC : public ClassA, public ClassB
{
public:
void FunctionA(){cout << "why" << endl;}
void FunctionB(){cout << "class C funb" << endl;}
};
ClassC aObject;
ClassA* pA = &aObject;
ClassB* pB = &aObject;
ClassC* pC = &aObject;
int main()
{
void* pvoid = static_cast<void *> (pB);
ClassA* pA2 = static_cast<ClassA*>(static_cast<ClassC*>(pB));
return 0;
}
类型转换是否pvoid
正确pA2
?还是两者都错了?(我尝试编译它,没有错误)