#pragma once
#include <time.h>
class CTimer
{
time_t _last;
CTimer() { _last = time( NULL ); }
CTimer(const CTimer &);
CTimer& operator=(const CTimer&);
~CTimer();
public:
static CTimer& getInstance(){
static CTimer instance;
return instance;
}
float getDelta(){
time_t now = time( NULL );
float delta = (float)(now - _last);
return delta;
}
//should be called at the beginning of rendering function
void update(){
_last = time( NULL );
}
};
This is my Timer singleton code. I wanted to use it like that: Somewhere in player class:
posX += vel * CTimer::getInstance().getDelta();
And in main loop file:
void gameLoop(){
CTimer::getInstance().update();
...
}
But I get this error:
1>Main.obj : error LNK2019: unresolved external symbol "private: __thiscall CTimer::~CTimer(void)" (??1CTimer@@AAE@XZ) referenced in function "void _cdecl
public: static class getInstance & __cdecl CTimer::getInstance(void)'::
2'::`dynamic atexit destructor for 'instance''(void)" (??_Finstance@?1??getInstance@CTimer@@SAAAV1@XZ@YAXXZ)
I think its because main code tries to call destructor, after loop ends and I should change to pointers singleton, but maybe not. Could you tell me how to fix this?