What is a non-trivial destructor in C++?

前端 未结 3 1683
情深已故
情深已故 2021-01-01 20:10

I was reading this which mentions destructors being trivial and non-trivial.

A class has a non-trivial destructor if it either has an explicitly def

3条回答
  •  死守一世寂寞
    2021-01-01 21:01

    You are getting your words mixed up. Your example does indeed declare an explicit destructor. You just forget to define it, too, so you'll get a linker error.

    The rule is very straight-forward: Does your class have an explicit destructor? If yes, you're non-trivial. If no, check each non-static member object; if any of them are non-trivial, then you're non-trivial.

提交回复
热议问题