我对 C++ 相当陌生,并且遇到了一个烦人的错误:这个以前的功能代码由于某种原因已经停止工作。编译后我得到的第一个错误如下所示。我认为由于某种原因它无法识别 enum type Material
,即使它是导入的。
1>...\chunk.h(10): error C2146: syntax error : missing ';' before identifier 'terrain'
1>...\chunk.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>...\chunk.h(10): error C2065: 'chunkWidth' : undeclared identifier
1>...\chunk.h(10): error C2065: 'chunkWidth' : undeclared identifier
1>...\chunk.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>...\world.h(14): error C2146: syntax error : missing ';' before identifier 'get'
1>...\world.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>...\world.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>...\world.h(14): warning C4183: 'get': missing return type; assumed to be a member function returning 'int'
1>...\world.h(6): error C2011: 'World' : 'class' type redefinition
1> ...\world.h(6) : see declaration of 'World'
1>...\world.cpp(9): error C2027: use of undefined type 'World'
1> ...\world.h(6) : see declaration of 'World'
块.h
#pragma once
#include "main.h"
class Chunk {
private:
int xpos;
int ypos;
public:
Chunk(int xRelToSpawn, int yRelToSpawn);
Material terrain[chunkWidth][chunkWidth];
int getXpos();
int getYpos();
};
主文件
#pragma once
#include "World.h"
//const int gridSizeX = 30;
//const int gridSizeY = 30;
const int chunkWidth = 15;
const int chunkHeight = 15;
extern int viewportX;
extern int viewportY;
const int viewportWidth = 15;
const int viewportHeight = 15;
enum Material{SAND, WATER};
extern World world = World();
世界.h
#include <vector>
#include "main.h"
#include "Chunk.h"
using namespace std;
class World {
private:
vector<Chunk> chunks;
public:
World();
~World();
bool chunkExists(int x, int y);
//returns material for absolute coordinates
Material get(int x, int y);
//returns world coordinates for given chunk coordinates
int* getAbsCoords(int chunkIndex, int x, int y);
int* getChunkCoords(int x, int y);
Chunk getChunk(int index);
int getChunkIndex(int x, int y);
int chunkIndexAbove(int chunkIndex);
int chunkIndexBelow(int chunkIndex);
int chunkIndexLeft(int chunkIndex);
int chunkIndexRight(int chunkIndex);
};
任何帮助表示赞赏。