ページ 11

龍神録プログラミング3章

Posted: 2013年9月21日(土) 23:02
by まつ

コード:

//受け取ったキー番号の現在の入力状態
	extern int CheckStateKey(unsigned char Handle);

	int ProcessLoop()
	{
		if (ProcessMessage()!=0)
		{
			return -1;
		}

		if(ClearDrawScreen()!=0)
		{
			return-1;
		}
		GetHitKeyStateAll_2();
		return0;
	}
龍神録プログラミングの3章でこのように入力したところ一番上の{でエラーが出てしまいます。
1 IntelliSense: ';' が必要です
という内容のものが出ますが、他に入力するべき場所がなさそうです。
どうしてこうなるのでしょうか。
何が間違っているのでしょうか。

Re: 龍神録プログラミング3章

Posted: 2013年9月21日(土) 23:05
by みけCAT
使用している開発環境は何ですか?
とりあえず、
return-1; → return -1;
return0; → return 0;
としてみてください。

Re: 龍神録プログラミング3章

Posted: 2013年9月21日(土) 23:07
by みけCAT
提示されているコードより前の部分が間違っているかもしれません。
このコード全体、includeしているファイル全体、includeしているファイルがincludeしているファイル全体・・・
を貼っていただけますか?
(DxLib.hやwindows.h、その他の標準ヘッダはいりません)

Re: 龍神録プログラミング3章

Posted: 2013年9月21日(土) 23:36
by まつ
先程より前のものは、
main.cpp

コード:

#define GLOBAL_INSTANCE
#include "DxLib.h"

int Key[256];

int GetHitKeyStateAll_2(int GetHitKeyStateAll_InputeKey[])
{
	//現在のキーの入力処理
	extern int GetHitKeyStateAll_2();

	//受け取ったキー番号の現在の入力状態
	extern int CheckStateKey(unsigned char Handle);
key.cpp

コード:

#include "DxLib.h"

unsigned int stateKey[256];

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

int CheckStateKey(unsigned char Handle){
        return stateKey[Handle];
}


です。

Re: 龍神録プログラミング3章

Posted: 2013年9月21日(土) 23:50
by みけCAT
main.cppに

コード:

#define GLOBAL_INSTANCE
#include "DxLib.h"

int Key[256];

int GetHitKeyStateAll_2(int GetHitKeyStateAll_InputeKey[])
{
	//現在のキーの入力処理
	extern int GetHitKeyStateAll_2();

	//受け取ったキー番号の現在の入力状態
	extern int CheckStateKey(unsigned char Handle);

	int ProcessLoop()
	{
		if (ProcessMessage()!=0)
		{
			return -1;
		}

		if(ClearDrawScreen()!=0)
		{
			return-1;
		}
		GetHitKeyStateAll_2();
		return0;
	}
と書いてあるということですか?
関数内で関数を定義するのはgcc拡張文法であり、さらにC++では使えないそうです。
普通に書いてください。

Re: 龍神録プログラミング3章

Posted: 2013年9月22日(日) 00:25
by まつ
ありがとうございます。
どうにかエラーはとれました。