I expected this code to print 'Same 1' and 'Same2', but it prints only 'Same1':
#include <iostream>
#include <typeinfo>
using namespace std;
struct C{virtual ~C(){}};
struct D : C{};
int main(){
D d;
C c, &cr1 = d;
if(typeid(cr1) == typeid(D)) cout << "Same1";
if(typeid(&cr1) == typeid(D*)) cout << "Same2";
}
Both §5.2.8/2 and §5.3.1/3 seem to suggest to me that 'Same2' should be printed.
What and where is the catch?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…