title: C++ Undefined abstract class constructor
body: <p>I've been having a bit of trouble lately in C++ with virtual methods/inheritance</p>
  
  <p>At first if i try to extend a super class i get this error:</p>
  
  <blockquote>
    <p>'Undefined reference to GameState::GameState()'</p>
  </blockquote>
  
  <p>but if i remove the constructors all together i don't get the above error but i end up with a segmentation fault which occurs when calling the virtual method.</p>
  
  <p>This is my code:</p>
  
  <pre><code>#ifndef GAMESTATE_H
  #define GAMESTATE_H
  
  #include &lt;stdlib.h&gt;
  
  #include "Resources.h"
  #include "Renderer.h"
  
  class GameState {
  public:
      GameState();
      virtual void init(Resources *res) = 0;
      virtual void exit() = 0;
      virtual void update() = 0;
      virtual void render(Renderer *renderer) = 0;
  };
  
  #endif // GAMESTATE_H
  </code></pre>
  
  <p>and this is the subclass:</p>
  
  <pre><code>#include "GameState.h"
  
  class MainGameState : public GameState {
  public:
      MainGameState() : GameState() {
  
      }
  
      virtual void init(Resources *res) {
  
      }
  
      virtual void update() {
          printf("test\n");
      }
  
      virtual void render(Renderer *renderer) {
  
      }
  
      virtual void exit() {
  
      }
  private:
      SDL_Surface *image;
  };
  </code></pre>