multiple definition error including c++ header file with inline code from multiple sources

前端 未结 6 1188
孤城傲影
孤城傲影 2020-12-01 04:41

I have a c++ header file containing a class. I want to use this class in several projects, bu I don\'t want to create a separate library for it, so I\'m putting both methods

6条回答
  •  爱一瞬间的悲伤
    2020-12-01 05:03

    Don't put a function/method definition in an header file unless they are inlined (by defining them directly in a class declaration or explicity specified by the inline keyword)

    header files are (mostly) for declaration (whatever you need to declare). Definitions allowed are the ones for constants and inlined functions/methods (and templates too).

提交回复
热议问题