エラー

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
hit

エラー

#1

投稿記事 by hit » 15年前

このソースで実行してみると、

1>c:\documents and settings\yoshimi\my documents\visual studio 2008\projects\test\test.cpp(23) : error C2086: 'int Key[256]' : 再定義されました。
1> c:\documents and settings\yoshimi\my documents\visual studio 2008\projects\test\test.cpp(3) : 'Key' の宣言を確認してください。

とエラーが起きてしまいます・・・どうしたら実行できますか?

#include "DxLib.h"

int Key[256];

int GetHitKeyStateAll_2(int GetHitKeyStateAll_InputKey[/url]){
char GetHitKeyStateAll_Key[256];
GetHitKeyStateAll( GetHitKeyStateAll_Key );
for(int i=0;i<256;i++){
if(GetHitKeyStateAll_Key==1) GetHitKeyStateAll_InputKey++;
else GetHitKeyStateAll_InputKey=0;
}
return 0;
}

void menu ( int white, int a)
{
DrawString( 150 , a , "◆" , white );
DrawString( 170 , 100 , "1" , white );
DrawString( 170 , 130 , "2" , white );
DrawString( 170 , 160 , "終了" , white );
}

int Key[256];
int white , a = 100;

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){
ChangeWindowMode(TRUE);//ウィンドウモード
if(DxLib_Init() == -1 || SetDrawScreen( DX_SCREEN_BACK )!=0) return -1;//初期化と裏画面化

while(ProcessMessage()==0 && ClearDrawScreen()==0 && GetHitKeyStateAll_2(Key)==0 && Key[KEY_INPUT_ESCAPE]==0){
//↑メッセージ処理   ↑画面をクリア     ↑入力状態を保存       ↑ESCが押されていない

int Key[256];
int white , a = 100;

white = GetColor( 255 , 255 , 255 ) ;

menu(white,a);

if( Key[KEY_INPUT_DOWN]==1 ||( Key[KEY_INPUT_DOWN]%5==0 && Key[KEY_INPUT_DOWN]>30)){
// たった今押したか、30カウンター以上押しっぱなしかつ5回に一度
a+=30;
if(a==160) // y座標が260なら(選択が一番下なら)
a=100; // 選択座標を一番上に
}




ScreenFlip();
}

DxLib_End();
return 0;
}

ideyan

Re:エラー

#2

投稿記事 by ideyan » 15年前

>1>c:\documents and settings\yoshimi\my documents\visual studio 2008\projects\test\test.cpp(23) : error C2086: 'int Key[256]' : 再定義されました。
23行目で変数Keyが再定義されました

>1> c:\documents and settings\yoshimi\my documents\visual studio 2008\projects\test\test.cpp(3) : 'Key' の宣言を確認してください。
3行目のKeyを確認してください

と書いてありますので、その通りにソースを見ると
int Key[256]が2回宣言されているのが分かります。

ですので、どっちかの宣言を削除すればエラーは消えると思いますよ^^

エラーは消えますが
>while(ProcessMessage()==0 && ClearDrawScreen()==0 && GetHitKeyStateAll_2(Key)==0 && Key[KEY_INPUT_ESCAPE]==0)
これの直後に再び
int Key[256];
int white , a = 100;
を宣言しちゃってるので、内部のif文が参照してる変数がおかしくなって
このプログラムは意図した動作をしないんじゃないかと思います。

no

Re:エラー

#3

投稿記事 by no » 15年前

「Key」が複数回再定義されているというエラーです。

一つお伺いしますが、C言語はどの程度勉強しましたか?
もしもほとんどやってないのなら、一度入門書を一冊終わらせることをおすすめします。

hit

Re:エラー

#4

投稿記事 by hit » 15年前

ありがとうございます!

hit

Re:エラー

#5

投稿記事 by hit » 15年前

解決!

閉鎖

“C言語何でも質問掲示板” へ戻る