putting function definitions in header files

后端 未结 4 486
情话喂你
情话喂你 2021-02-05 14:22

If you want to put function definitions in header files, it appears there are three different solutions:

  1. mark the function as inline
  2. mark the
4条回答
  •  执笔经年
    2021-02-05 14:51

    You could consider wrapping the methods in a class instead of a namespace. Declare these methods as static and delete the constructor of the class to reinforce that this is not an object to be instantiated.

    struct FooNamespace
    {
        FooNamespace() = delete;
    
        static FooMethod1() {
            ...
        }
        static FooMethod2() {
            ...
        }
    
    };
    

    You get the same general behavior as it belonging to a namespace with only a single implementation.

提交回复
热议问题