[英]C++ Boost errors in Visual Studio 2010 - errorLNK1104 and “Incompatible build options”
[英]Visual C++ Studio 2010 shows build errors for no reason
顯然,我不能在另一個類的公共部分中聲明一個類的實例。
我有兩節課:游戲和屏幕管理器。 如果我從Game.h中刪除以下行,一切都將成功編譯:
ScreenManager screenManager;
如果不這樣做,我會得到錯誤。 這些是我生成的錯誤消息:
1>c:\users\dziku\documents\visual studio 2010\projects\test allegro game\test allegro game\game.h(29): error C2146: syntax error : missing ';' before identifier 'screenManager'
1>c:\users\dziku\documents\visual studio 2010\projects\test allegro game\test allegro game\game.h(29): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\dziku\documents\visual studio 2010\projects\test allegro game\test allegro game\game.h(29): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Game.h:
#pragma once
#include"ScreenManager.h"
#include<allegro5\allegro.h>
#include<allegro5\allegro_image.h>
#include<allegro5\allegro_font.h>
#include<allegro5\allegro_ttf.h>
#include<allegro5\allegro_primitives.h>
class Game
{
public:
static const int WINDOW_WIDTH=800;
static const int WINDOW_HEIGHT=640;
static const int FPS=60;
float FRAME_INTERVAL;
bool isExiting;
float currentTime,prevTime,lag;
ALLEGRO_DISPLAY* display;
ALLEGRO_EVENT_QUEUE* eventQueue;
ALLEGRO_EVENT ev;
ScreenManager screenManager;
Game(void);
~Game(void);
static Game &getInstance();
void initialize();
void gameLoop();
void cleanup();
void update(ALLEGRO_EVENT &ev);
void render(ALLEGRO_DISPLAY* display);
};
和ScreenManager.h:
#pragma once
#include"Game.h"
#include<allegro5\allegro.h>
#include<vector>
#include<map>
class ScreenManager
{
public:
ScreenManager(void);
~ScreenManager(void);
void initialize();
void update(ALLEGRO_EVENT &ev);
void render(ALLEGRO_DISPLAY* display);
void unloadContent();
};
我真的不知道發生了什么,自昨天以來,我一直在其他項目中遇到類似的錯誤。 我一定在做錯事,但是我沒有任何線索,因此不勝感激。
您能解釋一下為什么標題"ScreenManager.h"
包含填充器"Game.h"
嗎?
ScreenManager.h:
#pragma once
#include"Game.h"
如果ScreenManager類成員函數使用Game類成員函數的某些數據成員,則應將類定義和uts成員函數的定義分開。 僅在類定義中聲明成員函數,並將其實現放置在某個單獨的模塊中。 如果需要,可以使它們內聯,以指定函數說明符內聯。
或者您可以將標頭ScreenManager中的Game類聲明為
class Game;
並在單獨的模塊中再次定義ScreeManager類的成員函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.