jeudi 6 septembre 2018

why it's different when use typeid to null pointer between polymorphic and non-poly?

A* a = nullptr;

try
{
    cout<<typeid(*a).name()<<endl;
}
catch(bad_typeid& tid)
{
    cout<<"agag"<<endl;
}

when class A is polymorphic, it throw bad_typeid exception. but when it's not polymorphic, it throw nothing. my question is why only polymorphic class throw bad_typeid exception when expression is null pointer de-reference?? and why they make mechanism like this? i don't understand thanks for your help.

Aucun commentaire:

Enregistrer un commentaire