c++ - Singleton destructor called error -
this question has answer here:
#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 = time( null ); float delta = (float)(now - _last); return delta; } //should called @ beginning of rendering function void update(){ _last = time( null ); } };
this timer singleton code. wanted use that: somewhere in player class:
posx += vel * ctimer::getinstance().getdelta();
and in main loop file:
void gameloop(){ ctimer::getinstance().update(); ... }
but 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 'instance''(void)" (??_finstance@?1??getinstance@ctimer@@saaav1@xz@yaxxz)
i think because main code tries call destructor, after loop ends , should change pointers singleton, maybe not. tell me how fix this?
if member of ctimer
class time_t
variable, don't need (not implemented, hence linking error) destructor, copy constructor , assignment operator. comment 3 lines: these functions generated compiler !
Comments
Post a Comment