我使用GCC,以及下面的代碼輸出令人意想不到的
#include <iostream>
#include <typeinfo>
using namespace std;
class B {
public:
B (B * ptr) { cout<< typeid(*ptr).name()<<endl;}
};
class D : public B {
public:
D() : B(this) { cout<<typeid(this).name()<<endl;}
};
int main()
{
D d;
return 0;
}
輸出:
1B
P1D
任何人都可以向我解釋爲什麼在這裏基類不能正確地告訴派生類的類型? 非常感謝
另請參閱:http://stackoverflow.com/q/10894683/1025391 – moooeeeep 2012-07-09 13:05:36