chr*_*423 1 c++
初学者问题:如何获取指针的地址并将其保存为int?例:
int *ptr = xyz; int i = static_cast<int>(ptr);
因此,如果ptr指向内存地址123,我应该是123.我的编译器说它是一个error: invalid static_cast from type 'int*' to type 'int'.
error: invalid static_cast from type 'int*' to type 'int'
猜猜我错过了什么,但我不知道是什么.
use*_*411 12
你可以用reinterpret_cast.一个int不能保证能够无损存储指针的,所以你应该使用std::intptr_t,而不是类型.
reinterpret_cast
int
std::intptr_t
归档时间:
11 年,10 月 前
查看次数:
5824 次
最近记录: