Why doesn't the C++ default destructor destroy my objects?

前端 未结 13 2127
刺人心
刺人心 2020-12-14 06:59

The C++ specification says the default destructor deletes all non-static members. Nevertheless, I can\'t manage to achieve that.

I have this:

class N         


        
13条回答
  •  星月不相逢
    2020-12-14 07:26

    Is there any reason why you use a pointer when the pointed-to object seems to belong the contained object? Just store the object by value:

    class M
    {
        N n;
    
    public:
    
        M() : n()
        {
        }
    };
    

提交回复
热议问题