gpt4 book ai didi

c++ - 访问冲突转换为 void* 并返回

转载 作者:太空宇宙 更新时间:2023-11-04 15:32:44 25 4
gpt4 key购买 nike

当我尝试以下操作时,我得到了一个访问冲突读取位置。我做错了什么?

uint64_t hInt = 2901924954136;
void* hPoint = reinterpret_cast<void*>(hInt);

uint64_t hIntBack = *static_cast<uint64_t*>(hPoint); //get access violation
here

最佳答案

我猜你是想将 hInt 的地址存储在 hPoint 中,而不是 hInt 的值。

uint64_t hInt = 2901924954136;
void* hPoint = reinterpret_cast<void*>(&hInt);
// ^ addressof operator

关于c++ - 访问冲突转换为 void* 并返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45657427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com