我目前正在为一款游戏制作插件,遇到以下问题:
我想让用户选择半径,但由于C++不允许我创建大小可变的数组,所以无法获得自定义半径。
这很好地解决了问题。
const int numElements = 25;
const int arrSize = numElements * 2 + 2;
int vehs[arrSize];
//0 index is the size of the array
vehs[0] = numElements;
int count = GET_PED_NEARBY_VEHICLES(PLAYER_PED_ID(), vehs);
但这个不会:
int radius = someOtherVariableForRadius * 2;
const int numElements = radius;
const int arrSize = numElements * 2 + 2;
int vehs[arrSize];
//0 index is the size of the array
vehs[0] = numElements;
int count = GET_PED_NEARBY_VEHICLES(PLAYER_PED_ID(), vehs);
有没有可能修改那个const int而不会产生错误?
int vehs[arrSize];
?
std::vector
吗? - R Sahustd::vector
有data()
成员函数,专门用于此。 - emlai