#include <cstdint>
constexpr uint32_t ticksPerSecond = 100000;
struct timemeasure {
constexpr explicit timemeasure(uint64_t c) : ticks(c) { }
uint64_t ticks;
constexpr timemeasure() : ticks(0) { }
};
struct time : timemeasure {
static volatile time now;
constexpr time() : timemeasure() { }
explicit time(uint64_t c) : timemeasure(c) { }
// Needed for `x = time::now`
explicit time(const volatile time &t) : timemeasure(t.ticks) { }
time& operator=(volatile time t) { ticks = t.ticks; return *this; }
};
inline time foo(const time& t) { return time(t.ticks + 1); }
给出编译错误:
prog.cpp: In function ‘time foo(const time&)’:
prog.cpp:22:57: error: no matching function for call to ‘time::time(time)’
prog.cpp:22:57: note: candidate is:
prog.cpp:14:15: note: constexpr time::time()
prog.cpp:14:15: note: candidate expects 0 arguments, 1 provided
为什么time::time(time)
试图被调用?肯定uint64_t
是不允许升职的吧?