Say that I have a void* containing a pointer to an unknown class. I want to use dynamic_cast to do run-time checking on the type of cl
To ensure dynamic_cast compiles and works, you should create an abstract or interface class with a virtual method.
#include
class Bar
{
public:
Bar() = default;
virtual ~Bar() = default;
};
class Foo : public Bar
{
public:
Foo() = default;
virtual ~Foo() = default;
};
int main()
{
Bar* bar = new Foo;
Foo* foo = dynamic_cast(bar);
assert(foo != nullptr);
}