title: C++ - Undefined reference to an object
body: <p>Compiler: MinGW
  <br>IDE: Code::Blocks
  <br>Platform: Windows XP
  <br>External libraries: SDL, SDL_image
  <br>What I'm trying to do: Cap the framerate at 60 frames per second using a timer that resets after each loop.
  <br>Just a warning, I AM inexperienced with C++, but I've done research and I can't find this kind of error anywhere else. I'm sure it has to do with scope, but I'm not sure how to resolve it.</p>
  
  <p><br>Compiler output:<br>
  <code>In function ZN4data6OnLoopEv':|'C:\Documents and Settings\Evan\My Documents\Programming Projects\Roguelike SDLtest 2\OnLoop.cpp|5|undefined reference to 'fps'</code></p>
  
  <p><code>C:\Documents and Settings\Evan\My Documents\Programming Projects\Roguelike SDLtest 2\OnLoop.cpp|7|undefined reference to 'fps'</code></p>
  
  <p><code>C:\Documents and Settings\Evan\My Documents\Programming Projects\Roguelike SDLtest 2\OnLoop.cpp|9|undefined reference to 'fps'</code></p>
  
  <p><strong>Main.cpp:</strong></p>
  
  <pre><code>#include "data.h"
  bool data::OnExecute()
  {
      if (OnInit() == false)
      {
          data::log("Initialization failure.");
          return 1;
      }
      SDL_Event Event;
      while(running == true)
      {
          fps.start();
          while(SDL_PollEvent(&amp;Event))
          {
              OnEvent(&amp;Event);
          }
          OnRender();
          OnLoop();
          log(convertInt(1000/fps.get_ticks()));
      }
      OnCleanup();
      data::log("Program exited successfully.");
      return 0;
  }
  </code></pre>
  
  <p><strong>data.h:</strong></p>
  
  <pre><code>#ifndef _DATA_H_
      #define _DATA_H_
  
  #include &lt;SDL/SDL.h&gt;
  #include &lt;SDL/SDL_image.h&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include "globals.h"
  
  class timer
  {
  private:
      int     startTicks; //Clock time at timer start
      bool    started;    //Timer status
      int     frame;
  
  public:
      void    Timer();  //Set timer variables
  
      //Clock actions
      void    start();
      void    stop();
  
      //Get timer status
      int     get_ticks();
  
      bool    is_started();   //Checks timer status
      void    incframe();
  };
  
  class data
  {
  private:
      timer fps;
      bool    running;
      SDL_Surface*    display;
      SDL_Surface*    tileset;    //The tileset
      SDL_Rect    clip[255];
      int     spritewidth;
      int     spriteheight;
      bool    mapfloor[80][24];     //Contains the locations of the floor and walls
      int    mapplayer[80][24];    //Contains the location of the player
      SDL_Rect   playersprite;       //Clip value of the sprite that represents the player
      std::string  tilesetdsk;    //Location of the tileset on disk
      std::string     debugfile;
      int     FRAMES_PER_SECOND;  //Max FPS
  
  public:
      data();
      bool    OnExecute();
      bool    OnInit();
      void    OnEvent(SDL_Event* Event);
      void    OnLoop();
      void    OnRender();
      void    OnCleanup();
      static  SDL_Surface*    load_image(std::string filename);
      static  void    apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip);
      void    LoadSprite();   //Determines what sprite is where in the tileset
      bool    levelgen();     //Generates a level
      void    log(std::string);          //**DEBUG** function for logging to file
      void    setvars();
      std::string convertInt(int number);
  };
  #endif
  </code></pre>
  
  <p><strong>OnLoop.cpp:</strong></p>
  
  <pre><code>#include "data.h"
  void data::OnLoop()
  {
      if(fps.get_ticks() &lt; 1000/FRAMES_PER_SECOND)
      {
          SDL_Delay((1000/FRAMES_PER_SECOND) - fps.get_ticks());
      }
      fps.incframe();
  }
  </code></pre>