下面这个类正在导致可怕的错误量。这似乎很好,但。谁知道为什么VC++讨厌我的任何C++专家?造成成千上万错误的文件(C++)
Entity.h
#pragma once
#include "World.h"
#include "Renderer.h"
class Entity {
public:
Entity(World* world, Coordinate coord);
~Entity();
void render(Renderer renderer) const;
World* world;
Coordinate coord;
};
Entity.cpp
#include "Entity.h"
Entity::Entity(World* world, Coordinate coord) : world(world), coord(coord) {
world->entities.insert(this);
}
Entity::~Entity() {
world->entities.erase(this);
}
这些错误本身并不构成一个整体非常有意义,因为他们甚至没有与此相关的文件。一些常见的错误是文件意外结束,缺少';'在“{”和“实体不是类或名称空间名称”之前。当我在项目中不包含实体时,不会发生这些错误。这些错误中的最后一个出现在实体的声明代码中。
的错误(删除所有重复):http://pastebin.com/TEMEhVZV
World.h
#pragma once
#include <map>
#include <vector>
#include <unordered_set>
#include "Chunk.h"
#include "Coordinate.h"
#include "Renderer.h"
class World {
public:
~World();
void generateChunk(Coordinate coord);
void loadChunk(Coordinate coord);
void renderWorld(Renderer* renderer);
std::unordered_set<Entity*> entities;
inline Chunk* getChunk(Coordinate coord) const {
return loadedChunks.at(coord);
}
private:
std::map<Coordinate, Chunk*> loadedChunks;
};
Renderer.h
#pragma once
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#include "World.h"
class Renderer {
public:
sf::Window *window;
void bind(sf::Window* newWindow);
void initializeOpenGL();
void renderChunk(Chunk* chunk);
inline void drawPoint(Coordinate coord) {
glBegin(GL_POINTS);
glVertex3d(coord.x, coord.y, coord.z);
glEnd();
}
private:
template <class T>
inline static void pushVector3(std::vector<T>* vertices, T x, T y, T z);
};
没有看到的错误,没有太多我们可以为您做 – Mgetz
世界应该是一个向前声明,而不是包括(除非这是坐标来自哪里,这将是奇怪的)。没有看到错误(至少向我们展示了第一对夫妇),这将很难提供帮助。 – crush
听起来像你可能在某处丢失某种结尾字符,如'}'或';'。这往往会导致一些荒谬的错误(通常是“意外的文件结束”),其中大部分几乎毫无意义 – wlyles