Moving inline methods from a header file to a .cpp files

前端 未结 6 1053

I have the following class defined in a foo.h header file

class Foo {

public:
    inline int Method();

};

inline int Foo::Method() { // Imple         


        
6条回答
  •  [愿得一人]
    2020-12-21 08:37

    It may be confusing, but you should not think of the purpose of inline to make the compiler inline a function. (Modern compilers are way smarter than you in regards to when a function should be inlined or not anyway).

    No, the real purpose of inline is to tell the linker to not worry about multiple definitions of the function. If you put the definition of a (non-member) function in a header, you should mark it inline to avoid linker errors.

提交回复
热议问题