Category Archives: c++

How slow are virtual methods in C++?

In one project I have a choice of modifying a behaviour of a class either by abstracting a base class with virtual methods and creating two descendant classes implementing those methods differently or by adding a flag and an "if" statement in the class and implementing the different behaviour based on the flag. Which one would you choose? Which one do you thing would be faster?