Virtual destructor: is it required when not dynamically allocated memory?

后端 未结 6 776
情书的邮戳
情书的邮戳 2020-12-05 07:53

Do we need a virtual destructor if my classes do not allocate any memory dynamically ?

e.g.

class A
{
      private: 
      int a;
      int b;

             


        
6条回答
  •  广开言路
    2020-12-05 08:25

    If your only concern is memory, maybe you should start by protecting base class destructor (and/or maybe others). Then if something does not compile, you'll see why. Ref: boost::any ways.

提交回复
热议问题