我觉得这个问题有点超出我的意思。我会很感激任何帮助。“术语不评估为全局对象中的函数......”
在UIM_Commander.cpp,我需要使用UIM_Parser
类中的(静态)方法。所以,在UIM_Commander.h,我包括UIM_Parser.h,就像这样:
#ifndef UIM_Commander_h
#define UIM_Commander_h
#include "..\sysm\SYSM.h"
#include "..\storm\STORM.h"
#include "..\ssqlm\SSQLM.h"
#include "..\inxm\INXM.h"
#include "UIM_Parser.h"
class UIM_Commander
{
.....
};
#endif
然而,这导致这个错误:
Error 8 error C2064: term does not evaluate to a function taking 0 arguments c:\workspace\sirenbase\sirenbase\uim\uim_main.cpp 3
UIM_Main.cpp:
#include "UIM_Main.h"
UIM_Commander commandCentre = UIM_Commander(); // <-- ERROR term does not evaluate to a function taking 0 arguments
list<string> stash;
int normal(int argc, char *argv[])
{
.....
}
int main(int argc, char *argv[])
{
.....
}
当然,我检查了UIM_Ma in.h中但似乎UIM_Commander.h已经包含有:
#ifndef UIM_Main_h
#define UIM_Main_h
#define NORMAL_MODE true //set this to false to run testmain
#include "..\storm\STORM.h"
#include "UIM_Commander.h"
#include "UIM_tokens.h"
#include "UIM_Parser.h"
#include <list>
#include <string>
#include <iostream>
#include <algorithm>
#include <cctype>
#include <vector>
using namespace std;
int main(int argc, char *argv[]);
int normal(int argc, char *argv[]);
#endif
全球,commandCentre
,在仅用于UIM_Parser.cpp,所以我不得不它作为UIM_Parser一个外部。^h:
#ifndef UIM_Parser_h
#define UIM_Parser_h
#include "UIM_Commander.h"
#include "UIM_Main.h"
#include "..\storm\STORM.h"
#include "UIM_tokens.h"
#include <list>
#include <string>
#include <sstream>
using namespace std;
extern UIM_Commander commandCentre; // <-- ALTERNATE ERROR missing ';' before identifier 'commandCentre'
//see below
extern list<string> stash;
class UIM_Parser
{
.....
};
#endif
如果它可以帮助任何在改变顺序UIM_Main.h到
#include "UIM_tokens.h"
#include "UIM_Parser.h"
#include "UIM_Commander.h"
改变错误
Error 1 error C2146: syntax error : missing ';' before identifier 'commandCentre' c:\workspace\sirenbase\sirenbase\uim\uim_parser.h 13
那么,我究竟做错了什么?这是一种奇怪的循环定义,包容卫兵不能救我?
编辑:
使用UIM_Commander commandCentre;
如果#include "UIM_Commander.h"
是#include "UIM_Parser.h"
前UIM_main.h改变错误
`Error 7 error C2086: 'int commandCentre' : redefinition c:\workspace\sirenbase\sirenbase\uim\uim_main.cpp 3
。如果#include "UIM_Parser.h"
是#include "UIM_Commander.h"
之前,则错误停留
Error 1 error C2146: syntax error : missing ';' before identifier 'commandCentre' c:\workspace\sirenbase\sirenbase\uim\uim_parser.h 13
再次编辑:我解决这得益于StevieG的答案。现在UIM_Parser.h看起来是这样的:
#ifndef UIM_Parser_h
#define UIM_Parser_h
#include "UIM_Main.h"
#include "..\storm\STORM.h"
#include "UIM_tokens.h"
#include <list>
#include <string>
#include <sstream>
using namespace std;
class UIM_Commander;
extern UIM_Commander commandCentre;
extern list<string> stash;
class UIM_Parser
{
.....
};
#endif
整齐漂亮,呵呵。
嗨,当我尝试这个,错误是不同的,但代码仍然不能编译。我用更多的信息编辑了我的问题。 – Naurgul
你确定所有'class'和'struct'结构都以分号结束吗? –
是的。问题是循环依赖。我认为现在已经解决了。我自己添加一个答案。无论如何感谢Kerrek! – Naurgul