how much does the default destructor do

后端 未结 5 2123
死守一世寂寞
死守一世寂寞 2021-02-14 04:11

Does the default destructor in C++ classes automatically delete members that are not explicitly allocated in code? For example:

class C {
  public:
    C() {}
           


        
5条回答
  •  走了就别回头了
    2021-02-14 04:45

    The implicitly defined (default) destructor will call the destructor for each member. In the case of a member array, it will call the destructor for each element of the array.

    Note that pointers don't have destructors; you need to manually delete them. You don't have this problem in the provided example, but it's something to be aware of.

提交回复
热议问题