Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi What are the Differences between dynamic_cast and typeid operator cast?
Posted

1 solution

Well, typeid doesn't really cast anything. It just lets you find out the type of an object.

dynamic_cast is a little bit clever, it will only let you cast from a derived class to its base class, or from a base class back to its derived class (assuming the base class object is actually of the derived class)

If you actually meant about casting like this:
MyClass a = (MyClass)SomeObject;


Then that kind of cast will pretty much allow anything.

Some handy things for you to read that google threw up:

Type casting operators in c++[^]
Demonstrating dynamic cast[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900