static_cast改变原指针的值

897阅读 0评论2010-12-06 maxxfire
分类:C/C++

在多重继承的时候有这种情况:

class B1
{
public:
    virtual void foo1(void) { }
protected:
    int m_b1;
};
 
class B2
{
public:
    virtual void foo2(void) { }
protected:
    int m_b2;
};
 
class D : public B1, public B2
{
public:
    virtual void foo3(void) { }
protected:
    int m_b3;
};
 
D d;
D* src = &d;
B2* dst = static_cast<B2*>(src);



保证指向正确的对象。




上一篇:[转]Mounting a hard disk image including partitions
下一篇:没有了