プロが教える店舗&オフィスのセキュリティ対策術

Visual C++ 2008 Express Edition を使っています。
シューティングゲームのサンプルで勉強しています。
すべで正常終了したあとダイヤログボックスが
出てくる時にMicrosoft Visual C++ Debug Library
と言うエラーが発生しました。
状況は以下のとおりです。

Program:C:\DxLib_VC\サンプルプログラム実行用フォルダ\Debug\DxLib_VC2008用.exe
Module:C:\DxLib_VC\サンプルプログラム実行用フォルダ\Debug\DxLib_VC2008用.exe
File:
Run-Time Check Failure #3 - The variable 'temp' is being used without being initialized
(Press Retry to debug the application)

Run-Timeの部分から自分なりに調べてみたのですが

ランタイム・チェック失敗#3-変数'temp'は初期化されずに使用されています。

と書いてあると思うのですが、tempの部分のコードは以下です。

(define.h)

struct E_SHOT{
bool flag;//弾が発射中かどうか
double x;//x座標
double y;//y座標
int gh;//グラフィックハンドル
int width,height;//画像の幅と高さ
int pattern;//ショットパターン
int speed;//弾スピード
};
#define ENEMY_SNUM 50//敵の弾の上限

(enemy.cpp)

int temp;
//弾画像読み込み
if(stype==0){
temp=LoadGraph("enemyshot1.png");
}
//サイズ取得
int w,h;
GetGraphSize(temp,&w,&h);
//弾の初期化
for(int i=0;i<ENEMY_SNUM;++i){
shot[i].flag=false;
shot[i].gh=temp;
shot[i].width=w;
shot[i].height=h;
shot[i].pattern=s_pattern;
shot[i].speed=speed;
shot[i].x=x;
shot[i].y=y;
}

正常終了後のエラーがなぜでるのかについてと、
その内容の部分について教えてください。
お願いします。

A 回答 (1件)

int temp;


//弾画像読み込み
if(stype==0){
 temp=LoadGraph("enemyshot1.png"); //←stype==0のときしかtempが初期化されない
}
//サイズ取得
int w,h;
GetGraphSize(temp,&w,&h); //←stype!=0のときのtempはどうなる?
//弾の初期化
for(int i=0;i<ENEMY_SNUM;++i){
 shot[i].flag=false;
 shot[i].gh=temp; //←stype!=0のときのtempはどうなる?
 shot[i].width=w;
 shot[i].height=h;
 shot[i].pattern=s_pattern;
 shot[i].speed=speed;
 shot[i].x=x;
 shot[i].y=y;
}


stype!=0のときもtempが初期化されるように直してみましょう。
    • good
    • 2

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!