title: Calling an empty base class function, what happens at compile time?
body: <p>How does the compiler treat a complete empty function to behave at runtime?</p>
  
  <pre><code>class Base
  {
      public:
      virtual void execute(){ /* always empty */ }
  };
  </code></pre>
  
  <p>example usage:</p>
  
  <pre><code>int main()
  {
  
      Base b;
      b.execute();
  
      return 0;
  
  }
  </code></pre>
  
  <hr>
  
  <p>Am creating an entity system which should be able to have sub-classes which are only holding data. Those are called <code>Properties</code>. Some need to have a manipulation function to conclude the data. These classes are called <code>Component</code>.</p>
  
  <p>The purpose is to be able to add functionality to a class at run-time and even later with additional shared libraries.</p>
  
  <p>Due to the flexibility needed, and the wish to keep it as simple as possible, I came up with a shared <code>Base</code> class for the <code>Properties</code> and <code>Component</code> classes. See the code-block below.</p>
  
  <p>However, the  class <code>Base</code> contains the function <code>execute()</code> and is invoked in the final class <code>Container</code> for all the properties and components assigned to that class.</p>
  
  <p>Maybe it is better to split the <code>Property</code> and <code>Component</code> entirely into two different identities, however they will rely on each other heavily, e.g. A property could be a transform (position, scale, quaternion, matrix) while a component can be an animation of that quaternion in the transform.</p>
  
  <pre><code>#include &lt;vector&gt;
  
  class Base
  {
      public:
      virtual void execute(){ /* always empty */ }
  };
  
  class Property // as manny will be
  : public Base
  {
      public:
      /* specifics */
  };
  
  class Component // as manny will be
  : public Base
  {
      public:
      /* specifics */
      virtual void execute(){ /* do whatever */ }
  };
  
  class Container
  {
      public:
      std::vector&lt;Base*&gt; list;
      virtual void execute()
      {
          std::vector&lt;Base&gt;::iterator iterator = list.begin(), end = list.end();
          while( iterator != end )
              ( *iterator )-&gt;execute();
      }
  
  }
  </code></pre>
  
  <p>Not knowing what the compiler actually does besides generating binaries, I don't think it would be an equivalent of a debug session going line by line.</p>
  
  <p>How does the compiler treat such an empty function, would it be better to move the <code>function execute();</code> to class <code>Component</code> as first declaration. Then add <code>enum{ Property, Component };</code> to class <code>Property</code> so a if-statement can determine to call the execution function.</p>