Will an 'empty' constructor or destructor do the same thing as the generated one?

前端 未结 7 1307
一生所求
一生所求 2020-11-28 18:49

Suppose we have a (toy) C++ class such as the following:

class Foo {
    public:
        Foo();
    private:
        int t;
};

Since no des

相关标签:
7条回答
  • 2020-11-28 19:44

    I agree with David except that I would say it is generally a good practice to define a virtual destructor i.e.

    virtual ~Foo() { }
    

    missing out virtual destructor can lead to memory leak because people who inherit from your Foo class may not have noticed that their destructor will never be called!!

    0 讨论(0)
提交回复
热议问题