I'm trying to make a class that will help me calculating the delta time in my game.
dt.h:
Code:
#include <ctime>
class dt
{
public:
void SetMaxFPS(int num);
void UpdateCurrentTicks();
void UpdateLastTicks();
long GetDeltaTime();
int GetFPS();
int GetMaxFPS();
bool UpdateNeeded();
private:
long GetTicks();
int max_fps;
int current_ticks;
int last_ticks;
};
The compiler put it pretty plainly. You are calling SetMaxFPS as if it was a static member, which it is not. Either make it static or instantiate an object of type dt.
The "make it static" suggestion is a mislead. While it's possible to do things that way, it probably isn't the *right* solution for this problem.
You have some fields in your dt class----last_ticks, etc. Where are these variables intended to live? You can either make them global, in which case you probably want dt to be a namespace rather than a class, or you can create a dt object to contain them. The latter is probably a better idea.
Thank you!
I have one more question,
how do I initialize a private int such as current_ticks to 0?
It wont let me initialize it to 0 in its definition.
Thank you!
I have one more question,
how do I initialize a private int such as current_ticks to 0?
It wont let me initialize it to 0 in its definition.
You can set the private member in every member function. For initialisation the constructor(s) are the right place and the most recommended way is to using the initializer list as shown by Amleto. However, you also could set it in the body of the constructor.
Code:
dt::dt()
{
current_ticks = 0;
}
It is not recommended to set it only before first use in a member function cause any instantiated object of the class (after constructing) should have a proper initialisation of its members.
Bookmarks