0

Typeid with virtual keyword not giving derived class name

Hi When I have pb2 as base* pointing to derived class object, does that not mean typeid on pb2 must be delivered class ? Am I missing something here? Refer code below: https://code.sololearn.com/cyJJPYTn7NcV/?ref=app

3rd Dec 2023, 5:12 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 ответов
+ 1
typeid of a pointer will always be the declared type, because that's the real type of the pointer itself. in order to know the real type of the object the pointer points to, you need to dereference the pointer to get the actual type : https://code.sololearn.com/cTJnOcJ6fcc5/?ref=app https://www.sololearn.com/en/compiler-playground/cTJnOcJ6fcc5
3rd Dec 2023, 10:56 PM
MO ELomari
MO ELomari - avatar
0
Thank you so much..!
4th Dec 2023, 8:27 AM
Ketan Lalcheta
Ketan Lalcheta - avatar