LoginSignup
5
4

More than 5 years have passed since last update.

c++/stl > STLコンテナクラスは仮想デストラクタを提供していない > このクラスから継承してはいけない

Last updated at Posted at 2015-08-24

引用: C++のためのAPIデザイン by マーティン・レディ
12.2 継承による拡張

だが、すでに述べたとおり、仮想デストラクタを定義するクラスからのみ派生すべきだ。STLコンテナクラスは仮想デストラクタを提供していない。実際、オーバーライドする仮想メソッドはまったくない。つまり、このクラスから継承してはいけないことを明示しているのだ。

関連して
http://stackoverflow.com/questions/1647298/why-dont-stl-containers-have-virtual-destructors

I think Stroustrup answered this question indirectly in his fantastic paper: Why C++ is not just an ObjectOriented Programming Language:
...
A virtual destructor is only useful for inheritance scenarios. STL containers are not designed to be inherited from (nor is it a supported scenario). Hence they don't have virtual destructors.

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4