class A
{
public:
A() : m_a(0)
{
printf("A::A\r\n");
}
virtual ~A()
{
printf("A::~A m_a=%d\r\n", m_a);
foo();
}
virtual void foo()
{
printf("A::foo\r\n");
}
int m_a;
};
class B : public A
{
public:
B() : m_b(0)
{
printf("B::B\r\n");
}
virtual ~B()
{
printf("B::~B m_b=%d\r\n", m_b);
foo();
}
virtual void foo()
{
printf("B::foo\r\n");
throw 1;
}
int m_b;
};
int _tmain(int argc, _TCHAR* argv[])
{
printf("Test 1:\r\n");
try
{
B b;
}
catch(int)
{
}
printf("Test 2:\r\n");
A a;
B *pB1 = (B*)&a;
B *pB2 = static_cast<B*>(&a);
B *pB3 = dynamic_cast<B*>(&a);
B *pB4 = reinterpret_cast<B*>(&a);
printf("&a=0x%x, pB1=0x%x, pB2=0x%x, pB3=0x%x, pB4=0x%x\r\n", &a, pB1, pB2, pB3, pB4);
printf("Test 3:\r\n");
pB1->foo();
pB1->m_b = 1;
printf("m_a=%d, m_b=%d\r\n", pB1->m_a, pB1->m_b);
return 0;
}
{
public:
A() : m_a(0)
{
printf("A::A\r\n");
}
virtual ~A()
{
printf("A::~A m_a=%d\r\n", m_a);
foo();
}
virtual void foo()
{
printf("A::foo\r\n");
}
int m_a;
};
class B : public A
{
public:
B() : m_b(0)
{
printf("B::B\r\n");
}
virtual ~B()
{
printf("B::~B m_b=%d\r\n", m_b);
foo();
}
virtual void foo()
{
printf("B::foo\r\n");
throw 1;
}
int m_b;
};
int _tmain(int argc, _TCHAR* argv[])
{
printf("Test 1:\r\n");
try
{
B b;
}
catch(int)
{
}
printf("Test 2:\r\n");
A a;
B *pB1 = (B*)&a;
B *pB2 = static_cast<B*>(&a);
B *pB3 = dynamic_cast<B*>(&a);
B *pB4 = reinterpret_cast<B*>(&a);
printf("&a=0x%x, pB1=0x%x, pB2=0x%x, pB3=0x%x, pB4=0x%x\r\n", &a, pB1, pB2, pB3, pB4);
printf("Test 3:\r\n");
pB1->foo();
pB1->m_b = 1;
printf("m_a=%d, m_b=%d\r\n", pB1->m_a, pB1->m_b);
return 0;
}