dynamic_cast(expression)
const_cast(expression)
static_cast(expression)

reinterpret_cast(expression)


class Base
{
public:
   virtual void fBase(){}
};

class A : public Base
{
public:
   int a;
};

class B : public Base
{
public:
   char b;
   char c;
   char d;
   char e;
};

class C
{
public:
   int a;
   char b;
   char c;
   int t;
   char d;
   char e;

};

void testFunc(Base *base)
{
   B *b = dynamic_cast(base);

   if (b) {
       printf("base is Class B\n");
   }
   else
   {
       printf("base is not Class B\n");
   }
}

int main(int argc, const char * argv[])
{
   A *a = new A;
   testFunc(a);
   B *b = new B;
   testFunc(b);
   printf("size of Base= %ld\n", sizeof(Base));
   printf("size of A = %ld\n", sizeof(A));
   printf("size of B = %ld\n", sizeof(B));
   printf("size of C = %ld\n", sizeof(C));
}


输出结果

base is not Class B
base is Class B
size of Base= 8
size of A = 16
size of B = 16
size of C = 16