2012-09-21 87 views
2

這可能很難解釋。我一直在使用MS VisC++ 2010 express開發一個程序大約一個月。我沒有遇到任何奇怪的問題,並準備第100次構建我的項目,突然間,許多.cpp文件似乎與.h文件的聯繫不密切。例如,在主函數中,幾周前創建並使用的對象突然在它們下面出現紅線,語法錯誤「theClass is undefined」。這適用於iostream,因此突然cout未定義。我不知道發生了什麼事。一秒鐘之後,所有外部頭文件和庫在IDE的眼中突然消失了。在.cpp文件,當我宣佈class constructorMS VisC++ 2010 express:突然項目不再看到頭文件

//initializes a poker game 
aPokerGame::aPokerGame(void) 
{ 
    stopPlaying = 'n';   
} 

我下得類名aPokerGame行,這錯誤是「must be a class or a namespace name」。這不是如果.h文件消失會發生什麼?其實並非所有的.cpp文件都有這個問題,只有一些。其他有像「沒有默認構造函數存在類」 std::basic_ostream<wchar...在他們真正奇怪的錯誤」。所有這些錯誤出現在天空中。

頭文件看起來不錯。雖然他們中的一個有‘Error: expected a declarationPrivate:‘標題’下的’ !爲私有成員

請幫

以下是編譯錯誤示例:

1>------ Build started: Project: firstProj, Configuration: Debug Win32 ------ 1> userPlayer.cpp 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.h(9): error C2504: 'Player' : base class undefined 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\iostream(10): error C2059: syntax error : 'namespace' 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\iostream(10): error C2334: unexpected token(s) preceding '{'; skipping apparent function body 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(8): error C3254: 'Player' : class contains explicit override '{ctor}' but does not derive from an interface that contains the function declaration 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(8): error C2838: '{ctor}' : illegal qualified name in member declaration 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(8): error C2535: 'Player::Player(void)' : member function already defined or declared 1>
c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\player.h(18) : see declaration of 'Player::Player' 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(13): error C3254: 'Player' : class contains explicit override '{dtor}' but does not derive from an interface that contains the function declaration 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(13): error C2838: '{dtor}' : illegal qualified name in member declaration 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(13): error C2535: 'Player::~Player(void)' : member function already defined or declared 1>
c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\player.h(19) : see declaration of 'Player::~Player' 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(18): error C3254: 'Player' : class contains explicit override 'userBets' but does not derive from an interface that contains the function declaration 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(18): error C2838: 'userBets' : illegal qualified name in member declaration 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.cpp(38): fatal error C1075: end of file found before the left brace '{' at 'c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\player.h(12)' was matched 1> pokerRound.cpp 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\npcplayer.h(9): error C2504: 'Player' : base class undefined 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\userplayer.h(9): error C2504: 'Player' : base class undefined 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\iostream(10): error C2059: syntax error : 'namespace' 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\iostream(10): error C2334: unexpected token(s) preceding '{'; skipping apparent function body 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\time.h(35): error C2059: syntax error : 'string' 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\time.h(35): error C2334: unexpected token(s) preceding '{'; skipping apparent function body 1>c:\users\bn\dropbox\myprojects\mysoftware\c++\firstproj\firstproj\pokerround.cpp(16): error C2059: syntax error : 'namespace'

+2

也許你在類定義之後丟失了一個分號,或者你在頭文件中包含了''include''到一些標準頭文件之上的其他文件,這會讓一切都變得糟糕,並且編譯器會報告錯誤只是錯誤,因爲你忘記了一條小路。仔細檢查每個頭文件的語法,尋找不匹配的圓括號或大括號,並確保在需要的地方使用分號。 –

+0

謝謝Seth :)我正在檢查所有.h文件,有時如果我只保存一個文件,它會清除依賴於它的頭文件。不過,有一件事情,主流中的iostream如何關閉? cout在它工作數週的主類中是未定義的。任何與此構建錯誤:「1> C:\程序文件(x86)\微軟視覺工作室10.0 \ vc \包括\ iostream(10):錯誤C2059:語法錯誤:'命名空間'」 – user442920

+0

好吧,問題解決了。再次感謝賽斯。完全按照您的建議,缺少頂部.h文件中的分號和分號。那是一個心臟停止器。 – user442920

回答

7

也許你缺少的一類definiti後分號或者類似於頭文件中的一些文件,這些文件包含在一些標準頭文件之上的其他文件中,這使得一切都變得混亂起來,編譯器會報告錯誤,因爲您忘記了一條小東西。

仔細檢查每個頭文件的語法,查找不匹配的圓括號或大括號,並確保在需要的地方使用分號。

相關問題