These C ++ conversion operators should be used as
dynamic_cast<newType>(variable)
In your case
m* q = dynamic_cast<m*>(p);
By the way, do you confuse the role mand n? n* p = new mis a syntax error because an instance of a base class cannot be implicitly converted to an instance of a derived class. In fact, the base → received by you is a situation when you really need it dynamic_cast, and not vice versa (casting is not required).
Also, consider providing meaningful names to objects.
source
share