How do you update/reassign a class member Chrono::timestamp for rolling elapse times

  Kiến thức lập trình

How do you re-assign a class member chrono time_point variable?

I skimmed through the hour long video from {@Howard Hinnant} and I didn’t see anything referencing what I need.

Time Output Class

#include <iostream>
#include <chrono>
#include <cstdint>
namespace chrono = std::chrono;
namespace chrono_lit = std::chrono_literals;
using namespace chrono_lit;

class TrackTimeElapse {
  public:
    TrackTimeElapsed(uint64_t interval):
      m_timestamp(chrono::steady_clock::now()), m_interval(interval) {}
    ~TrackTimeElapsed() {}
    void trackTime() {
      chrono::time_point<chrono::steady_clock> now = chrono::steady_clock::now();
      auto diff = chrono::duration_cast<std::chrono::seconds>(now - m_timestamp);
      if (diff.count() > m_interval) {
        std::cout << "Time elapsed" << std::endl;
        // Update timestamp to help track when next print out needs to occur.
        m_timestamp = now; // Issue here due to assignment operator not being defined.
      }
    }
  private:
    chrono::time_point<chrono::steady_clock> m_timestamp;
    uint64_t m_interval;
};

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT