Why does enable_shared_from_this have a non-virtual destructor?

后端 未结 3 1475
轻奢々
轻奢々 2021-02-07 04:21

I have a pet project with which I experiment with new features of C++11. While I have experience with C, I\'m fairly new to C++. To train myself into best practices, (besides re

3条回答
  •  深忆病人
    2021-02-07 04:26

    is there a proper way to deal with this?

    Don't use -Weffc++ all the time. It's useful to turn it on sometimes to check your code, but not really to use it permanently. It gives false positives and is not really maintained these days. Use it now and then, but be aware you might have to ignore some warnings. Ideally, just memorise all the advice in the Meyers books and then you don't need it anyway ;-)

    am I correct in thinking that this destructor is bogus, or is there a real purpose to it?

    No, it's not bogus and has a real purpose. If it wasn't defined it would be implicity-declared as public, to prevent that it is explicitly declared as protected.

提交回复
热议问题