我的代码有问题。旨在将值保存到结构数组中。但是,有两件事是随机发生的-1)数组可能为空,或者2)数组可能仅包含一行值。
struct MacroMas
{
int x;
int y;
int Delay;
int SemiAutoDelay;
int ammo;
MacroMas* Cords(int x, int y, int Delay)
{
MacroMas _ret;
_ret.x = x;
_ret.y = y;
_ret.Delay = Delay;
return _ret;
}
};
MacroMas* temp()
{
MacroMas _ret;
MacroMas* macroMasArray = new MacroMas[107];
for (int index = 0; index <107 ; ++index)
macroMasArray[index] = MacroMas();
macroMasArray[0].Cords(-3, 4, 16);
macroMasArray[1].Cords(-3, 4, 17);
// Some more code
return macroMasArray;
答案 0 :(得分:0)
首先是Cords函数:函数将返回MacroMas *,并且您返回MacroMas类型的对象,这是您的代码中的错误。
在这两行中您犯了一个错误
setId
Cords函数具有返回值 当macroMasArray [0]或[1]调用Cords时,对它们不起作用。 您需要像这样存储它们
macroMasArray[0].Cords(-3, 4, 16);
macroMasArray[1].Cords(-3, 4, 17);
或在Cords Body中使用此指针。
macroMasArray[0] = macroMasArray[0].Cords(-3, 4, 16);