Is a destructor considered a const function?

后端 未结 2 987
误落风尘
误落风尘 2020-12-09 16:02

Consider this

class Foo
{
public:
    Foo(){}
    ~Foo(){}
    void NonConstBar() {}
    void ConstBar() const {}
};

int main()
{
    const Foo* pFoo = new          


        
2条回答
  •  不思量自难忘°
    2020-12-09 17:01

    The lifetime of an object ends (for the owner/enclosing scope) as soon as the destructor is invoked, not when the destructor returns.

    Therefore I don't see any problem deleting constants. It's already gone for you when you call delete.

    Otherwise deleting constant objects would require a const_cast.

提交回复
热议问题