I have a program I'm working on that is currently split up into multiple .cpp and their respective header files, and a main.cpp.
In main.cpp, I include a header for a Timer class, and from within main(), I create Timer objects
Timer regulate; Timer update; Timer fps;
From within main.cpp, I can have each Timer object call its Class' functions.
Example:
fps.start(); fps.stop();
What I have done is try to have main() run the main loop, and use OOP to split up all of the different features of the program.
I am trying to work with a piece of code, but I don't want it in main. I want it to be taken care of by a function in another file, Game.cpp. void Game::Update()
if(regulate.get_ticks() < 1000/FRAMES_PER_SECOND)
{
SDL_Delay((1000/FRAMES_PER_SECOND) - regulate.get_ticks());
}
if (update.get_ticks() > 1000)
{
std::stringstream calculatedFPS;
calculatedFPS << "Avg FPS: " << frame/(fps.get_ticks() / 1000.f);
displayFPS = TTF_RenderText_Solid(font, calculatedFPS.str().c_str(), textColor);
update.start();
}
I'm obviously getting errors because Game.cpp does not know about the existence of the Timer objects that I have created from within main.cpp.
How do I let a function in Game.cpp work with these objects from the Timer.cpp class created from within Main.cpp?
The Errors:
1>c:\users\jeremy\documents\programming\sdltutorials\sdltutorials\game.cpp(130) : error C2065: 'regulate' : undeclared identifier
1>c:\users\jeremy\documents\programming\sdltutorials\sdltutorials\game.cpp(130) : error C2228: left of '.get_ticks' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jeremy\documents\programming\sdltutorials\sdltutorials\game.cpp(132) : error C2065: 'regulate' : undeclared identifier
1>c:\users\jeremy\documents\programming\sdltutorials\sdltutorials\game.cpp(132) : error C2228: left of '.get_ticks' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jeremy\documents\programming\sdltutorials\sdltutorials\game.cpp(135) : error C2065: 'update' : undeclared identifier
1>c:\users\jeremy\documents\programming\sdltutorials\sdltutorials\game.cpp(135) : error C2228: left of '.get_ticks' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jeremy\documents\programming\sdltutorials\sdltutorials\game.cpp(138) : error C2065: 'fps' : undeclared identifier
1>c:\users\jeremy\documents\programming\sdltutorials\sdltutorials\game.cpp(138) : error C2228: left of '.get_ticks' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\jeremy\documents\programming\sdltutorials\sdltutorials\game.cpp(140) : error C2065: 'update' : undeclared identifier
1>c:\users\jeremy\documents\programming\sdltutorials\sdltutorials\game.cpp(140) : error C2228: left of '.start' must have class/struct/union
1> type is ''unknown-type''

New Topic/Question
Reply



MultiQuote




|