What is wrong with using inline functions?

后端 未结 12 1287
滥情空心
滥情空心 2020-11-29 01:51

While it would be very convenient to use inline functions at some situations,

Are there any drawbacks with inline functions?

Conclusion:

12条回答
  •  伪装坚强ぢ
    2020-11-29 02:16

    I agree with the other posts:

    • inline may be superfluous because the compiler will do it
    • inline may bloat your code

    A third point is it may force you to expose implementation details in your headers, .e.g.,

    class OtherObject;
    
    class Object {
    public:
        void someFunc(OtherObject& otherObj) {
            otherObj.doIt(); // Yikes requires OtherObj declaration!
        }
    };
    

    Without the inline a forward declaration of OtherObject was all you needed. With the inline your header needs the definition for OtherObject.

提交回复
热议问题