inline function linker error

前端 未结 5 1843
面向向阳花
面向向阳花 2020-12-08 02:47

I am trying to use inline member functions of a particular class. For example the function declaration and implementation without inlining is as such:

in the header

5条回答
  •  臣服心动
    2020-12-08 03:10

    You need to put function definition into the header then. The simplest way to hint the compiler to inline is to include method body in the class declaration like:

    
    class NeedleUSsim
    {
      // ...
      int GetTplLSize() const { return sampleDim[1]; }
      // ...
    };
    

    or, if you insist on separate declaration and definition:

    
    class NeedleUSsim
    {
      // ...
      int GetTplLSize() const;
      // ...
    };
    
    inline int NeedleUSsim::GetTplLSize() const
    { return sampleDim[1]; }
    

    The definition has to be visible in each translation unit that uses that method.

提交回复
热议问题