Avoiding virtual method calls
February 12 2010
I was about to write a post about how to avoid virtual method calls in C++.
While looking for the correct wording for one of the lines I stumbled across this: Getting rid of virtual method calls
Since my explanation wasn’t much better, I’ll just leave you with the link to Floh’s article and a snippet of our rendering engine.
[renderer.hpp]
#if defined( OM_PLATFORM_IPHONE )
#include "iphone/renderer_iph.hpp"
namespace OM
{
#define Renderer OM::Renderer_Iph
}
#elif defined( OM_PLATFORM_OSX )
#include "osx/renderer_osx.hpp"
namespace OM
{
#define Renderer OM::Renderer_Osx
}
[...]
[renderer_osx.hpp]
namespace OM
{
class Renderer_Osx : public RendererBase
{
public:
[...]
Just one more thing to say: This works perfectly for us on the 9 supported platforms.