linking error2005 visual studio 2008 c++

后端 未结 2 1706
走了就别回头了
走了就别回头了 2021-01-27 15:38

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 y

2条回答
  •  半阙折子戏
    2021-01-27 15:48

    I believe you should organize the code as:

    yacc.h   //-----> should have declaration of errQueue & errorStruct
    
    yacc.cc  //-----> should include yacc.h, 
    //It can create variables of type errQueue & errorStruct
    
    node.cc  //-----> should include yacc.h
    //It can create variables of type errQueue & errorStruct
    

    Note that the declarations should only be present in yacc.h and it should be included in all your cc files which need to create instances of the said types, If the structures are declared in any of your cc file in addition to the header(yacc.h) then you will end up getting the redefinition errors you mentiones.

提交回复
热议问题