【发布时间】:2017-06-23 11:19:39
【问题描述】:
所以我有两个数组来保存玩家 x、y 和 z 坐标,但是每次我调用它们时,它们会在第一次打印到控制台时更改它们的值,它们会显示正确的结果,但是随后会打印到屏幕上产生非常小的数字,
HisPosition = GetPlayerPosition(aPlayer);
std::cout << "TheirPos=" << std::dec << HisPosition[0] << std::endl;
std::cout << "TheirPos1=" << std::dec << HisPosition[0] << std::endl;
if(!isnan(HisPosition[0])){
std::cout << "TheirPos2=" << std::dec << HisPosition[0] << std::endl;
控制台输出示例:
TheirPos=440
TheirPos1=1.7118e-037
TheirPos2=1.7118e-037
它们的定义如下:
float* HisPosition;
还有GetPlayerPosition:
float* GetPlayerPosition(DWORD dwBase)
{
float result [3];
DWORD aXPos = dwBase + 0x134;
DWORD aYPos = dwBase + 0x138;
DWORD aZPos = dwBase + 0x13C;
result[0] = Read<float>(aXPos);
result[1] = Read<float>(aYPos);
result[2] = Read<float>(aZPos);
return result;
}
aPlayer 代表我试图获取的玩家内存中的地址,偏移量是正确的,因为在第一个控制台打印位置是正确的。
我是在 C++ 中使用数组的新手,希望得到任何指导。
【问题讨论】:
-
return result;返回一个指向数组的指针,然后在返回时立即销毁该数组。你有未定义的行为。