我需要键入指向无符号int值的强制转换自定义类指针。这是我累的地方。
Class A{
};
int main()
{
A* a = foo();
unsigned int handler = reinterpret_cast<unsigned int>(a);
return 0;
}它给出了警告warning C4302: 'reinterpret_cast': truncation from 'A *' to 'unsigned int'
用C++方式克服这一问题的正确方法是什么?
发布于 2015-03-18 04:12:17
此错误可能意味着您正在编译到64位目标,在这种情况下,指针是64位,将_cast重解释为int意味着截断(因为int最多为32位)。
不确定您将如何处理处理程序,但更安全的方法是在uintptr_t可用的情况下将其转换为c++11。
http://en.cppreference.com/w/cpp/types/integer
包括<cstdint>,应该是这样的,
uintptr_t handler = reinterpret_cast<uintptr_t>(a);https://stackoverflow.com/questions/29113889
复制相似问题