我有一个Parser.h
, 定义了一个 struct StmtParent
:
...
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
...