开篇先说这道面试题:

class ClassA
{
public:
virtual ~ ClassA()
{
}
virtual void FunctionA()
{
}
};
class ClassB
{
public:
virtual void FunctionB()
{
}
};
class ClassC: public ClassA, public ClassB
{
public:
};
ClassC aObject;
ClassA *pA = &aObject;
ClassB *pB = &aObject;
ClassC *pC = &aObject;

  

假设定义了ClassA* pA2,下面正确的代码是:
pA2=static_cast<ClassA*>(pB);
void* pVoid=static_cast<void*>(pB); pA2=static_cast<ClassA*>(pVoid);
pA2=pB;
pA2=static_cast<ClassA*>(static_cast<ClassC*>(pB)); //正确答案BD

  

05-07 15:51