How do I create a header-only library?

前端 未结 4 1903
花落未央
花落未央 2020-12-23 02:29

I\'d like to package a library I\'m working on as a header-only library to make it easier for clients to use. (It\'s small and there\'s really no reason to put it into a sep

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 03:04

    Use header guards as Liz suggests and don't forget to put "inline" before your function methods.

    ie

    #ifndef MY_HEADER_H_
    #define MY_HEADER_H_
    
    inline RetType FunctionName( ParamType1 param1, ParamType2 param2 )
    {
        // Function body
        return retType;
    }
    
    #endif
    

提交回复
热议问题