Are there any specific reasons to use non-virtual destructors?

前端 未结 5 1882
不思量自难忘°
不思量自难忘° 2020-12-30 01:13

As I know, any class that is designated to have subclasses should be declared with virtual destructor, so class instances can be destroyed properly when accessing them throu

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 01:38

    Why are destructors not virtual by default? http://www2.research.att.com/~bs/bs_faq2.html#virtual-dtor

    Guideline #4: A base class destructor should be either public and virtual, or protected and nonvirtual. http://www.gotw.ca/publications/mill18.htm

    See also: http://www.erata.net/programming/virtual-destructors/

    EDIT: possible duplicate? When should you not use virtual destructors?

提交回复
热议问题