C++ &引用;错误C2059:语法错误:';如果'&引用;(Visual C+;+;2010专业版)

C++ &引用;错误C2059:语法错误:';如果'&引用;(Visual C+;+;2010专业版),c++,syntax,C++,Syntax,在谷歌搜索之后,我发现我在“如果”之前遗漏了一些东西。 据我所知,没有。 说真的,我错过了什么? 我在第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 "Characte

在谷歌搜索之后,我发现我在“如果”之前遗漏了一些东西。 据我所知,没有。 说真的,我错过了什么? 我在第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?)

“如果”在全局范围内。你必须把它放在一个方法/函数中。

你必须简单地把
if
放在某个函数中。在C/C++中,除了变量/数据结构/函数等之外,编写一些代码。函数外的声明是非法的。

如果
语句需要在函数体中,搜索Google的语法错误通常是无用的,因为每次都取决于上下文。在写东西之前,你应该知道语法)