Repeated Multiple Definition Errors from including same header in multiple cpps

后端 未结 9 1648
南方客
南方客 2020-11-27 06:12

So, no matter what I seem to do, I cannot seem to avoid having Dev C++ spew out numerous Multiple Definition errors as a result of me including the same header file in multi

9条回答
  •  北海茫月
    2020-11-27 06:44

    To expand on what Gerald said, the header is defining an instance of the struct (which is not what you want). This is causing each compilation unit (cpp file) which includes the header to get its own version of the struct instance, which causes problems at link time.

    As Gerald said, you need to define a reference to the struct (using 'extern') in the header, and have one cpp file in your project which instantiates the instance.

提交回复
热议问题