问题描述
我有struct errorStruct&在yacc.y中的队列errQueue定义,然后将其移动到单独的.h文件
,但它给我的链接错误,定义在yacc.obj和node.obj中找到!!
尝试创建新解决方案但仍然给出相同的错误
I had struct errorStruct & a queue errQueue definition in yacc.y , then moved it to separate .h file
but it gives me linking error that the definition is found in both yacc.obj and node.obj !!
tried creating new solution but still gives the same error
Error 9 error LNK2005: "class std::queue<struct errorStruct,class std::deque<struct
errorStruct,class std::allocator<struct errorStruct> > > errQueue" (?errQueue@@3V?$queue@UerrorStruct@@V?
$deque@UerrorStruct@@V?$allocator@UerrorStruct@@@std@@@std@@@std@@A) already defined in Node.obj yacc.obj
更新
首先:
节点。 h // for node class
yacc.y // rules + errorStruct + queue errQueue + class ErrList:includesNode.h& <队列>
update
first :
Node.h // for node class
yacc.y // rules + errorStruct + queue errQueue + class ErrList : includes "Node.h" & < queue>
然后:
Node.h // for node class + errorStruct + queue errQueue + class ErrList :包括<队列>
yacc.y //规则:包括Node.h
Node.h // for node class + errorStruct + queue errQueue + class ErrList : includes < queue>
yacc.y // rules : includes "Node.h"
in Node.h
in Node.h
struct errorStruct{
int errLineNum;
int errColNum ;
char * errMessage;
};
class ErrList{
public:
void pushError(int line,int col,char * message);
void popError();
void printErrors();
int getSize();
private :
queue <errorStruct> errQueue;
};
externErrList * se = new ErrList ();
Node.h的其余部分与此类无关
yacc.y只是使用
se-> pushError(...);
和作为没有类ErrList的声明或errQueue
the rest of Node.h has nothing to do with this class
in yacc.y just usingse->pushError(...);
and as no declaration of class ErrList or errQueue
推荐答案
opss!我忘了张贴答案..对不起..
opss! I forgot to post the answer .. sorry ..
得到了@Peter K.的参考资料:
got it with the help of @Peter K.'s reference :
转到VS:project - >属性页 - >配置属性 - > linker - >命令行
go to VS : project -> property page -> configuration properties -> linker ->command line
并添加 / FORCE :MULTIPLE
在其他选项框中
这篇关于链接error2005 visual studio 2008 c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!