Can I get polymorphic behavior without using virtual functions?

You could down cast the base class pointer to the derived class and call the function.

Base* obj = new Derived;
Derived* d = static_cast<Derived*>( obj ); 
d->doSomething();

Since doSomething() is not declared virtual, you should get the derived implementation.

Leave a Comment