Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6625207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:44:45+00:00 2026-05-25T21:44:45+00:00

Compiler: MinGW IDE: Code::Blocks Platform: Windows XP External libraries: SDL, SDL_image What I’m trying

  • 0

Compiler: MinGW

IDE: Code::Blocks

Platform: Windows XP

External libraries: SDL, SDL_image

What I’m trying to do: Cap the framerate at 60 frames per second using a timer that resets after each loop.

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.

Compiler output:
In function ZN4data6OnLoopEv':|'C:\Documents and Settings\Evan\My Documents\Programming Projects\Roguelike SDLtest 2\OnLoop.cpp|5|undefined reference to 'fps'

C:\Documents and Settings\Evan\My Documents\Programming Projects\Roguelike SDLtest 2\OnLoop.cpp|7|undefined reference to 'fps'

C:\Documents and Settings\Evan\My Documents\Programming Projects\Roguelike SDLtest 2\OnLoop.cpp|9|undefined reference to 'fps'

Main.cpp:

#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(&Event))
        {
            OnEvent(&Event);
        }
        OnRender();
        OnLoop();
        log(convertInt(1000/fps.get_ticks()));
    }
    OnCleanup();
    data::log("Program exited successfully.");
    return 0;
}

data.h:

#ifndef _DATA_H_
    #define _DATA_H_

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <string>
#include <fstream>
#include <sstream>
#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

OnLoop.cpp:

#include "data.h"
void data::OnLoop()
{
    if(fps.get_ticks() < 1000/FRAMES_PER_SECOND)
    {
        SDL_Delay((1000/FRAMES_PER_SECOND) - fps.get_ticks());
    }
    fps.incframe();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:44:46+00:00Added an answer on May 25, 2026 at 9:44 pm

    fps is a variable of type timer, declared in data::OnExecute().

    However, you also reference fps in another method data::OnLoop(), where fps is out of scope.

    To fix this, I recommend making fps a member-variable of class data. Then fps will always be available inside all the methods of data.

    Do this by declaring fps right with your other member-variables
    (in the private: section of class data)
    Remove the declaration in data::OnExecute().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OS: Windows 7 Compiler: MinGW IDE: Code::Blocks I just installed Gtkmm on my computer
I'm compiling using Code::Blocks on Windows 7 using the MinGW compiler (which I can
I am compiling with MinGW in Windows 7, using Code::Blocks as the IDE. Everything
I have been using the gcc compiler with code::blocks ide, and have noticed there
I used code:blocks as the C++ IDE on Windows. I switched to netbeans 6.8
I am running Code::Blocks 10.05 with the MingW compiler package on a Win7-32 box.
OS: Windows 7 Pro X64 IDE: Eclipse IDE for C/C++ Developers Compiler: MinGW (lastest,
Is the latest binary release of Code::Blocks with MinGW setup compatible with Windows 7?
Is there possibility to compile windows service using only mingw c++ compiler and library?
I am trying to use MinGW to compile a C program under Windows XP.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.