C++: Multiple definition error for global functions in the header file

后端 未结 5 1447
陌清茗
陌清茗 2021-02-12 17:52

This function is global and is defined in the header file (temporarily I want to keep it there).

The header file also constitutes a particular class which has i

5条回答
  •  清歌不尽
    2021-02-12 18:10

    mark it as inline:

     inline void globalfunc() { 
     }
    

    although doing so means that it will no longer strictly be global - you will get a copy in each translation unit that uses the header, but the linker won't object to this.

提交回复
热议问题