What's the point in defaulting functions in C++11?

后端 未结 8 1463
失恋的感觉
失恋的感觉 2020-12-03 03:41

C++11 adds the ability for telling the compiler to create a default implementation of any of the special member functions. While I can see the value of deleting a function,

8条回答
  •  臣服心动
    2020-12-03 03:48

    1) Implicitly generated destructors are currently not virtual. So you need to define them in order to make them virtual, in which case they are not as efficient. With =default, You will have both virtual and efficent as implicitly generated destructors.

    2) They will have access specifiers, contrary to implicitly generated ones.

    3) If you inline your defaulted constructor, your class still remain trivial.

    Here is an article elaborating this new feature.

提交回复
热议问题