此代码:
constexpr uint32_t ticksPerSecond = 100000;
struct ticks {
uint32_t count;
template<typename integer>
constexpr explicit ticks(integer c) : count(c) { }
explicit inline operator float() {
return count / (float) ticksPerSecond;
}
};
template<>
constexpr explicit ticks::ticks<float>(float s) : count(s * ticksPerSecond) { }
给我错误:
timer.hpp:(last line of snippet):
error: only declarations of constructors can be 'explicit'
当然ticks::ticks
是构造函数吗?
答案 0 :(得分:11)
错误消息非常清楚,您只能在声明中使用explicit
(不在定义中)。只需从专业化中删除该关键字:
template<>
constexpr ticks::ticks<float>(float s) : count(s * ticksPerSecond) { }