在阅读https://blog.csdn.net/albertsh/article/details/118663176与https://blog.csdn.net/qq_28127741/article/details/120625183?ops_request_misc=%257B%2522request%255Fid%2522%253A%25221FECE3BF-9D92-47F3-9715-57137BE79CEB%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=1FECE3BF-9D92-47F3-9715-57137BE79CEB&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-120625183-null-null.142v100pc_search_result_base3&utm_term=dynamic_pointer_cast&spm=1018.2226.3001.4187这两篇文章中关于dynamic_cast的内容后,发现有冲突。
例1
#include
using namespace std;
//父亲:老王
class LaoWang
{
public:
LaoWang() :m_LaoWangMoney(10) {}
~LaoWang() {}
virtual void money() {
std::cout << m_LaoWangMoney << std::endl;
}
int m_LaoWangMoney;
};
//儿子:小明
class XiaoMing :public LaoWa