0
我有一個Parser.h
,定義一個結構StmtParent
:錯誤使用單元測試(CppUnit的),在另一個文件中定義的結構
...
struct StmtParent;
class Parser {
...
然後在Parser.cpp
:
struct StmtParent {
int stmtNo;
int parent;
};
...
似乎沒事吧?然後,我有一個單元測試(CppUnit的):
# in ParserUnitTests.h
#include "header\Parser.h"
# in ParserUnitTests.cpp
void ParserUnitTests::testParseProcSideEffects() {
...
stack<StmtParent> follows;
...
然後我得到這樣的錯誤:
error C2027: use of undefined type 'StmtParent'
爲什麼,我可以使用功能,如Parser::parseLine()
。爲什麼我不能訪問結構?所以我嘗試了Parser.h
在ParserUnitTests.cpp
(儘管我已經將它包含在標題中)。然後我得到:
Error 8 error C2146: syntax error : missing ';' before identifier 'm_cCurToken' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\parser.h 52
Error 9 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\microsoft sdks\windows\v7.0a\include\parser.h 52
Error 10 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\microsoft sdks\windows\v7.0a\include\parser.h 52
...
發現我需要在頭文件中定義結構 –