为什么你需要一个C风格的演员阵容?
int* ptr = static_cast<int*>(0xff); // error: invalid static_cast from type 'int'
// to type 'int*'
int* ptr = (int*) 0xff; // ok.
Run Code Online (Sandbox Code Playgroud)
Rem*_*eau 18
static_cast只能在两个相关类型之间进行转换.整数与指针无关,反之亦然,因此您需要使用reinterpret_cast,它告诉编译器重新解释整数的位,就像它们是指针一样(反之亦然):
int* ptr = reinterpret_cast<int*>(0xff);
Run Code Online (Sandbox Code Playgroud)
阅读以下内容了解更多详情:
| 归档时间: |
|
| 查看次数: |
4645 次 |
| 最近记录: |