私は単純なゲームを作ろうとしています。他のすべてのヘッダー ファイル (B と呼びましょう) を含むヘッダー ファイル (A と呼びましょう) を含むメインの .cpp ファイルがあります。programRunning
これらの B ヘッダー ファイルの 1 つに、定義されているブール値にアクセスするための A ファイルを含めました。変数を定義する A ファイルが含まれているにもかかわらず、B ヘッダー ファイルはどれも使用できないようです。私はこれに本当に混乱しており、助けていただければ幸いです。以下は私が使用したコードです:
pong_header.h (上記の A ヘッダー ファイル)
#ifndef PONG_HEADER_H
#define PONG_HEADER_H
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <stdio.h>
#include "pong_graphics.h"
#include "pong_core.h"
#include "pong_entity.h"
#include "pong_event.h"
bool programRunning;
#endif
pong_event.h (B ヘッダー ファイルの 1 つ)
#ifndef PONG_EVENT_H
#define PONG_EVENT_H
#include "pong_header.h"
void Pong_handleEvents(SDL_Event event)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
programRunning = true;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym):
case SDLK_ESCAPE:
programRunning = false;
break;
break;
default:
break;
}
Pong_handleEntityEvents(event)
}
}
他の B ファイルも同様にアクセスprogramRunning
します。
Code::Blocks が私に与える正確なエラーは次のとおりです。
Pong\pong_event.h|20|error: 'programRunning' was not declared in this scope