c++ - Attempt to cast std::chrono::duration gives "rep cannot be a duration" compilation error -


sure i'm doing dumb here i'm having trouble compiling simple stopwatch class. error is:

/usr/include/c++/4.9/chrono:246:2: error: static assertion failed: rep cannot duration

i want cast difference in time between 2 std::chrono::high_resolution_clock milliseconds. i'm sure code used work (false memory or perhaps better standards impl 2015 on 2013).

the repo here.

#include <iostream> #include <chrono>  class stopwatch final { public:      using elapsed_resolution = std::chrono::milliseconds;     using elapsed_duration = std::chrono::duration<std::chrono::milliseconds>;      stopwatch()     {         reset();     }      void reset()     {         reset_time = clock.now();     }      elapsed_duration elapsed()     {         return std::chrono::duration_cast<elapsed_resolution>(clock.now() - reset_time);     }  private:      std::chrono::high_resolution_clock clock;     std::chrono::high_resolution_clock::time_point reset_time; };  int main(void) {     auto s = stopwatch();      std::cout << s.elapsed().count() << std::endl; } 

this line here:

using elapsed_duration = std::chrono::duration<std::chrono::milliseconds>; 

needs this:

using elapsed_duration = std::chrono::duration<float, std::milli>; 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -