Why must a pure virtual destructor's implementation be empty? And should it be inline?

前端 未结 4 991
春和景丽
春和景丽 2021-02-19 10:30

I read in other threads that when you implement a pure virtual destructor (yes it can have an implementation) it must be empty, and should (?) be inline. Should it be empty? If

4条回答
  •  自闭症患者
    2021-02-19 10:48

    Keeping in mind that 'must' and 'should' mean different things...

    A pure virtual destructor can be non-empty. Don't know who might have said otherwise.

    Should it be? Yes, since an abstract base should not have anything to delete. You will find that you'll violate this latter 'should' from time to time and thus, of course, may the former as well.

    Should it be inline? It neither should nor should not. I can't think of anything you clearly gain by it being "inline" since implementations are both free to ignore inlines and to inline non-inlines. Generally though there's no reason to create an implementation file for nothing more than an empty destructor in an abstract class.

提交回复
热议问题