나는 다음과 같이 디버깅을위한 스톱워치를 구현하기 위해 노력하고 있습니다 :C++ 표준 크로노 오버 플로우
#include <chrono>
namespace sbstd
{
class timer
{
private:
bool m_running = false;
std::chrono::time_point<std::chrono::system_clock> m_temp;
std::chrono::nanoseconds m_time;
public:
void start()
{
if (m_running) { throw std::exception("timer already running"); }
m_temp = std::chrono::system_clock::now();
m_running = true;
}
void stop()
{
if (!m_running) { throw std::exception("timer not started"); }
m_time += std::chrono::system_clock::now() - m_temp;
m_running = false;
}
long long get_ms() const
{
return std::chrono::duration_cast<std::chrono::milliseconds>(m_time).count();
}
};
}
을 주요 방법 나는 다음과 같은 한 대신 5000의
sbstd::timer t1;
t1.start();
std::this_thread::sleep_for(std::chrono::seconds(5));
t1.stop();
cout << t1.get_ms();
내가 부정적인 INT를 얻을 수 .
무엇이 잘못 되었나요?
'm_time'의 초기 값은 무엇입니까? 언제 어디에서 재설정합니까? –