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

后端 未结 5 1999
夕颜
夕颜 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:55

    The compiler is free to inline code that you have not declared inline, and is free not to inline code that you have declared inline. I have seen compilers do both of these things. Because of this the inline keyword does not mean what most people think it does. It's meaning is to allow an exception to the one definition rule, so you can put functions etc. in a header file and not get linker errors.

    So the advice is rubbish, let the compiler decide what is best to inline and what is not. Put inline where you need it to prevent linker errors, that is all.

提交回复
热议问题