Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不提数组的腐败 我对C++很陌生,我想知道为什么我的数组会被破坏。在腐蚀弹药库之前,它会多次通过双for循环,尽管在该行之前它被正确分配。然后,它给出了写入冲突的错误 class bullet{ public: int x, y, damage, speed; char direction; }; bullet * ammo_bank[100]; void render(player avatar, riflemen enemy){ bullet projectile; int counter1, counter2, icurrentammo; icurrentammo = current_ammo -1; for (counter1 = 0; counter1 <=SCREEN_HEIGHT; counter1++){ for (counter2 = 0; counter2 <=SCREEN_WIDTH; counter2++){ // corruption occurs a few times before here screen[counter1][counter2] = '.'; } } system("cls"); screen [avatar.y][avatar.x] = AVATAR_SYMBOL; screen [enemy.y][enemy.x] = RIFLEMEN_SYMBOL; while (icurrentammo >= 0){ projectile = *ammo_bank[icurrentammo]; // Writing error screen[projectile.x][projectile.y] = BULLET_SYMBOL; projectile.x ++; icurrentammo --; } for (counter1 = 0; counter1 <=SCREEN_HEIGHT; counter1++){ cout << endl; for (counter2 = 0; counter2 <=SCREEN_WIDTH; counter2++){ cout << screen[counter1][counter2]; } } void playerShoot(player avatar){ ammo_bank[current_ammo] = new bullet(); // Create the MyClass here. bullet projectile = *ammo_bank[current_ammo]; projectile.x = avatar.x + 1; projectile.y = avatar.y; projectile.speed = 2; projectile.direction = 'f'; projectile.damage = 1; *ammo_bank[current_ammo] = projectile; current_ammo++; } 类项目符号{ 公众: 智力x,y,伤害,速度; 煤焦方向; }; 子弹*弹药库[100]; 虚空渲染(玩家化身,步枪兵敌人){ 弹丸; int计数器1、计数器2、icurrentammo; icurrentammo=当前弹药-1; 对于(counter1=0;counter1_C++_Visual Studio 2010 - Fatal编程技术网

不提数组的腐败 我对C++很陌生,我想知道为什么我的数组会被破坏。在腐蚀弹药库之前,它会多次通过双for循环,尽管在该行之前它被正确分配。然后,它给出了写入冲突的错误 class bullet{ public: int x, y, damage, speed; char direction; }; bullet * ammo_bank[100]; void render(player avatar, riflemen enemy){ bullet projectile; int counter1, counter2, icurrentammo; icurrentammo = current_ammo -1; for (counter1 = 0; counter1 <=SCREEN_HEIGHT; counter1++){ for (counter2 = 0; counter2 <=SCREEN_WIDTH; counter2++){ // corruption occurs a few times before here screen[counter1][counter2] = '.'; } } system("cls"); screen [avatar.y][avatar.x] = AVATAR_SYMBOL; screen [enemy.y][enemy.x] = RIFLEMEN_SYMBOL; while (icurrentammo >= 0){ projectile = *ammo_bank[icurrentammo]; // Writing error screen[projectile.x][projectile.y] = BULLET_SYMBOL; projectile.x ++; icurrentammo --; } for (counter1 = 0; counter1 <=SCREEN_HEIGHT; counter1++){ cout << endl; for (counter2 = 0; counter2 <=SCREEN_WIDTH; counter2++){ cout << screen[counter1][counter2]; } } void playerShoot(player avatar){ ammo_bank[current_ammo] = new bullet(); // Create the MyClass here. bullet projectile = *ammo_bank[current_ammo]; projectile.x = avatar.x + 1; projectile.y = avatar.y; projectile.speed = 2; projectile.direction = 'f'; projectile.damage = 1; *ammo_bank[current_ammo] = projectile; current_ammo++; } 类项目符号{ 公众: 智力x,y,伤害,速度; 煤焦方向; }; 子弹*弹药库[100]; 虚空渲染(玩家化身,步枪兵敌人){ 弹丸; int计数器1、计数器2、icurrentammo; icurrentammo=当前弹药-1; 对于(counter1=0;counter1

不提数组的腐败 我对C++很陌生,我想知道为什么我的数组会被破坏。在腐蚀弹药库之前,它会多次通过双for循环,尽管在该行之前它被正确分配。然后,它给出了写入冲突的错误 class bullet{ public: int x, y, damage, speed; char direction; }; bullet * ammo_bank[100]; void render(player avatar, riflemen enemy){ bullet projectile; int counter1, counter2, icurrentammo; icurrentammo = current_ammo -1; for (counter1 = 0; counter1 <=SCREEN_HEIGHT; counter1++){ for (counter2 = 0; counter2 <=SCREEN_WIDTH; counter2++){ // corruption occurs a few times before here screen[counter1][counter2] = '.'; } } system("cls"); screen [avatar.y][avatar.x] = AVATAR_SYMBOL; screen [enemy.y][enemy.x] = RIFLEMEN_SYMBOL; while (icurrentammo >= 0){ projectile = *ammo_bank[icurrentammo]; // Writing error screen[projectile.x][projectile.y] = BULLET_SYMBOL; projectile.x ++; icurrentammo --; } for (counter1 = 0; counter1 <=SCREEN_HEIGHT; counter1++){ cout << endl; for (counter2 = 0; counter2 <=SCREEN_WIDTH; counter2++){ cout << screen[counter1][counter2]; } } void playerShoot(player avatar){ ammo_bank[current_ammo] = new bullet(); // Create the MyClass here. bullet projectile = *ammo_bank[current_ammo]; projectile.x = avatar.x + 1; projectile.y = avatar.y; projectile.speed = 2; projectile.direction = 'f'; projectile.damage = 1; *ammo_bank[current_ammo] = projectile; current_ammo++; } 类项目符号{ 公众: 智力x,y,伤害,速度; 煤焦方向; }; 子弹*弹药库[100]; 虚空渲染(玩家化身,步枪兵敌人){ 弹丸; int计数器1、计数器2、icurrentammo; icurrentammo=当前弹药-1; 对于(counter1=0;counter1,c++,visual-studio-2010,C++,Visual Studio 2010,screen[][]是如何声明的。如果它是screen[screen_HEIGHT][screen_WIDTH],那么你的问题是你正在使用我今天买了一本书,它叫做“Accelerated C++”),这和任何东西有什么关系更新你的示例以显示你是如何声明screen的。另外,你可能想查看screen[sparlet.x][sparlet.y]=BULLET\u SYMBOLsparlet.x=0&&sparket.y=0,但如果我这样做的话,它会在底部产生这些奇怪的ASCII字符that@user

screen[][]是如何声明的。如果它是screen[screen_HEIGHT][screen_WIDTH],那么你的问题是你正在使用我今天买了一本书,它叫做“Accelerated C++”),这和任何东西有什么关系更新你的示例以显示你是如何声明screen的。另外,你可能想查看
screen[sparlet.x][sparlet.y]=BULLET\u SYMBOL
sparlet.x=0&&sparket.y=0
,但如果我这样做的话,它会在底部产生这些奇怪的ASCII字符that@user998335点是数组的索引从0到count-1,因此非常常见的是查找(i=0;i@MartyE+1,另外,请注意,对当前弹药没有限制或检查,因此弹药库[100]也可以是overrun@user998335如果在将数组修复为not overflow后,最后一行出现奇怪的字符,则可能还需要将显示循环修复为not overflow。