itsacoaster

inexplicable c++ behavior

Jan 26th, 2023 (edited)
1,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. struct TimedEvent {
  2.     EventType_t event;
  3.     std::chrono::duration<long double> timestamp;
  4.    
  5. /* //adding this section makes it work
  6.     template <class T, class U>
  7.     TimedEvent(EventType_t && e, std::chrono::duration<T, U> && t) {
  8.         event = std::move(e);
  9.         timestamp = std::move(t);
  10.     }
  11. */
  12. };
  13.  
  14. std::vector<TimedEvent> timedEvents;
  15.  
  16. auto t1 = TimedEvent{a1, std::chrono::seconds(1000)}; //works
  17. auto t2 = TimedEvent(a1, std::chrono::seconds(1000)); //doesn't compile without the added constructor
  18. //also doesn't work, probably for the same reason:
  19. //timedEvents.emplace_back(std::move(a1), std::chrono::seconds(1000)); //doesn't compile without the added constructor
  20.  
  21.  
Advertisement
Add Comment
Please, Sign In to add comment