64位中指针和int的模板重载问题

Template overload issues with pointers and ints in 64 bit

本文关键字:重载 问题 int 指针 64位      更新时间:2023-10-16

我的模板有问题,并将不匹配的指针重载为int。

C:/Users/Bakaiya/Desktop/Onathe/src/AdminPlanetPresentation.cpp:24:66:错误:从"AdminPlanet*"转换为"int"会丢失精度[-fpermission]U: :log(U::c("+创建行星表示",int(target));

我对"c()"模板有几个重载,但我当前的问题围绕着为什么我最近添加的指针重载不能解决这个问题。

template<class T>
inline String c( T a )
{
    return Ogre::StringConverter::toString( a );
}
template<class T>
inline String c( T* a )
{
    return c( (uint64_t)a );
}

以及多参数模板:

template<class T, typename... Args>
inline String c( T a, Args... args );
template<class T, typename... Args>
inline String c( T* a, Args... args );
...
template<class T, typename... Args>
inline String c( T a, Args... args )
{
    return Ogre::StringConverter::toString( a ) + c( args... );
}
template<class T, typename... Args>
inline String c( T* a, Args... args )
{
    return c( a ) + c( args... );
}

以前我构建的是32位,让指针隐式转换到通用模板c( T a )是没有问题的。不过,在64位构建中,这还不够。

为什么重载没有捕获指针并阻止它们隐式转换为int?

这里提供了包含其他重载和模板的完整文件。

根据链接的代码,问题是U::log( U::c( " + Creating planet representation ", int( target ) ) );中的int( target ),与此处显示的代码无关。

请改用uintptr_t(target)