This is valid C, but not C ++; they are two different languages, even if they have many common features.
In C ++, there is no implicit conversion from void* to a typed pointer, so you need to throw. You should prefer C ++ casting, as they limit which conversions are allowed, and therefore help prevent errors:
s = static_cast<char*>(p);
Even better, you should use polymorphic methods (for example, abstract base classes or patterns) to avoid the need to use untyped pointers in the first place; but it is rather beyond the scope of this question.
source share