【c++11关键字】dynamic_cast
作者:
小鱼号的代码日记 | 来源:发表于
2020-10-21 10:36 被阅读0次/*
* c++11关键字
* dynamic_cast
* 小鱼号的代码日志
*/
#include <QCoreApplication>
#include <iostream>
using namespace std;
struct Base
{
virtual ~Base()
{}
};
struct Derived :Base
{
virtual void name()
{
}
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Base *b1 = new Base;
if(Derived *d = dynamic_cast<Derived *>(b1))
{
cout <<"down cast b1 to d successful";
}
Base *b2 = new Derived;
if(Derived *d = dynamic_cast<Derived *>(b2))
{
cout <<"down cast b2 to d successful";
}
Base bb;
Derived& cc = dynamic_cast<Derived&>(bb); ///bad
return a.exec();
}
本文标题:【c++11关键字】dynamic_cast
本文链接:https://www.haomeiwen.com/subject/oshhmktx.html
网友评论