64位中指针和int的模板重载问题
Template overload issues with pointers and ints in 64 bit
我的模板有问题,并将不匹配的指针重载为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)
。
相关文章:
- 一个关于在C++中重载布尔运算符的问题
- 在C++中使用重载提取运算符时出现问题
- 重载运算符与添加问题
- 加、乘、除、减复数的问题 C++ - 运算符重载
- 0xC0000005:访问冲突读取位置 0x00000000. 重载 == 运算符的问题
- 关于重载 -> 运算符中 const 关键字的特定位置的问题
- 基于 SFINAE 的特征实现问题与函数模板重载
- C++使用模板参数来解决重载问题
- 为什么C++在自定义结构向量时会出现 ostream 重载问题?
- 链表运算符重载问题
- glUniforms()和[]运算符重载问题
- C++类型重载问题
- C++中的通用访问者基类模板-重载问题
- 64位中指针和int的模板重载问题
- 操作符+重载问题
- 操作符重载问题
- 操作符重载问题
- 操作符重载问题
- c++歧义重载问题
- 运算符重载问题C++