Why are inline constructors and destructors not a good idea in C++?

后端 未结 5 1991
夕颜
夕颜 2021-02-01 21:20

I remember reading in one of the C++ books (quite some time ago) that it is not a good idea to have inline Constructors and Destructors especially for derived class. I understa

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-01 22:04

    Apart from the reason @oli mentions in his answer:

    The book probably guides on not inlining constructors and destructors, because even seemingly trivial or empty functions might often contain lot of implicitly generated code by the compiler and the actual function definition might end up being quite large, This might result in code bloat.

    Having said so, It is prudent to let the compiler actually decide whether to inline or not inline a function call (even constructors and destructors), most of modern day compilers will appropriately optimize functions through in-lining.

提交回复
热议问题