从object转换为int会丢失精度C++

-4 c++ casting

在我的TimeCode.h中,我有以下内容:

inline TimeCode::operator int() const;
Run Code Online (Sandbox Code Playgroud)

每当我将TimeCode对象转换为int时,应该能够执行哪个.

但当我做类似的事情时:

(int) firstTimeCode > (int) scndTimeCode
Run Code Online (Sandbox Code Playgroud)

编译器向我抛出以下错误:

cast from 'TimeCode*' to 'int' loses precision [-fpermissive]
Run Code Online (Sandbox Code Playgroud)

有谁知道问题是什么以及如何解决?非常感谢你提前!

Cho*_*ett 6

看看错误信息-它告诉你,你转换TimeCode*int-那就是你的操作数的至少一个是指针TimeCode,不是实际的TimeCode.因此,您需要首先取消引用该指针以正确调用您的运算符.