c++ - "error C2059: syntax error : ' 如果 '"(Visual C++ 2010 专业版)

标签 c++ syntax

经过 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?)

最佳答案

“if”是全局范围的。您必须将其放入方法/函数中。

关于c++ - "error C2059: syntax error : ' 如果 '"(Visual C++ 2010 专业版),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14081547/

相关文章:

c - C中括号中两个值的赋值

c++ - 为什么标准布局类的成员必须具有相同的访问控制?

c++ - 引用作为 std::map 中的键

c++ - 为什么在 C++ 中获取日期和/或时间如此复杂?

c++ - typedef 声明语法

python - 我已经使用这个文档字符串语法两年了,它叫什么,谁指定它,使用它是 "ok"吗?

函数结束后的 C++ 变量

c++ - 调用派生类的虚函数时出现段错误

sql-server - SQL Server : query to get multiple results in one field

Objective-C 我可以简写 += 增量属性吗?