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

后端 未结 5 1992
夕颜
夕颜 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 21:52

    I'm pretty sure this is not about what C++ does with the code, because, as said, it's just a hint.

    If you start looking at software engineering consideration things change. All inline function changes will force recompilations of all dependent files.

    It get worse when you maintain a library and want to send out a bug fix version, remaining ABI compatible. Inline functions can simply not be replaced by another version because the calling code may not be recompiled. So where your non-inline function can be replaced at will, you have to move to a new version of your interface when inline functions ned to be changed.

    Combine this with the fact that constructors can seldom be actually inlined by the compiler, then you I can imagine why a book would give the advice mentioned.

提交回复
热议问题