用codeblock typeid(i).name()跟老师的不一样,为啥嘞
int i; cout<<typeid(i).name()<<endl;
输出的是 i
int main(){ Rect re; Circle cl; doSomething(&cl); return 0;}
void doSomething(Shape *test){ test->calc_area(); cout<<typeid(*test).name()<<endl; if(typeid(*test) == typeid(Rect)) { Rect *rect = dynamic_cast<Rect *>(test); rect->the_rect(); }}
输出的是前面带了个数字的类