fork download
  1. #include <iostream>
  2. #include <time.h>
  3. using namespace std;
  4.  
  5. class CTimer
  6. {
  7. time_t _last;
  8. CTimer() { _last = time( NULL ); }
  9. CTimer(const CTimer &);
  10. CTimer& operator=(const CTimer&);
  11. ~CTimer()
  12. {}
  13. public:
  14. static CTimer& getInstance(){
  15. static CTimer instance;
  16. return instance;
  17. }
  18.  
  19. float getDelta(){
  20. time_t now = time( NULL );
  21. float delta = (float)(now - _last);
  22. return delta;
  23. }
  24. //should be called at the beginning of rendering function
  25. void update(){
  26. _last = time( NULL );
  27. }
  28. };
  29.  
  30. int main()
  31. {
  32. cout<<"ok";
  33. int vel = 4;
  34. int posX = (vel * CTimer::getInstance().getDelta());
  35. return 0;
  36. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
ok