下面這個類正在導致可怕的錯誤量。這似乎很好,但。誰知道爲什麼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