2

Google 検索の後、「if」の前に何かが欠けていることがわかりました。私が見る限りではありません。真剣に、私はここで何が欠けているのですか? 44行目にこのエラーがあります。すべての括弧とセミコロンが明確にあります。

#include "Entity.h"
#include "string.h"
#include "surface.h"
#include "stdlib.h"
#include "template.h"
#include "SDL.h"
#include "game.h"
#include "Ghosts.h"
#include "Character.h"
#include "Tile.h"

using namespace Tmpl8;

Surface* Map = new Surface("assets/map.png");
Surface* Spook = new Surface("assets/ghost.png");
Surface* Player = new Surface("assets/char.png");
Sprite* Play = 0;
Invader Invaders[55];
Character c;

Tile* myTile = new Tile(96,96); //Define new tile.
Tile* tileArray[3000/96][3280/96]; //Define size total tiles.

TileProperties myTileset[2] = {
    {true,  0,  0}, //Tile 0 = solid wall, graphics at 0,0
    {true, 96,  0} //Tile 1 = open space, graphics at 96,0
};

const int MAP_WD = 5;
const int MAP_HT = 5;

int map[MAP_WD * MAP_HT] = {
    1,1,1,1,1,
    1,1,0,0,1,
    1,0,0,0,1,
    1,0,1,0,1,
    1,1,1,1,1
};

const TileProperties& GetTile(int x, int y) {
    return myTileset[map[(y*MAP_HT) + x]];
}

if (GetTile(c.Xpos, c.Ypos).Wall) { //Here's the trouble.

}

エラー:

1>c:\nhtv\year 1\block b\pr2\f. gauntlet\game.cpp(44): error C2059: syntax error : 'if'
1>c:\nhtv\year 1\block b\pr2\f. gauntlet\game.cpp(44): error C2143: syntax error : missing ';' before '{'
1>c:\nhtv\year 1\block b\pr2\f. gauntlet\game.cpp(44): error C2447: '{' : missing function header (old-style formal list?)
4

2 に答える 2

3

「if」はグローバルスコープです。あなたはそれをメソッド/関数の中に入れなければなりません。

于 2012-12-29T12:16:04.337 に答える
0

単にif何らかの関数に入れる必要があります。変数/データ構造/関数など以外のコードを書くなど、関数の外での宣言はC / C ++では違法です。

于 2012-12-29T12:21:10.393 に答える