reinterp.cpp

来自「数值计算工具库,C语言编写的,可以直接调用.」· C++ 代码 · 共 39 行

CPP
39
字号
// Reinterpret cast

#include <typeinfo>  

class Dog {
public:
    Dog() { }
    virtual void fetch() = 0;
};

class Dalmation : public Dog {
public:
    Dalmation() { }
    virtual void fetch();
};

void Dalmation::fetch()
{
}

class Unrelated {
public:
    Unrelated() { }

};

void foo(Unrelated&)
{ }

int main()
{
    Dalmation cairo;
    Dog& dog = cairo;
    Unrelated& eek = reinterpret_cast<Unrelated&>(dog);
    foo(eek);
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?