Should I store entire objects, or pointers to objects in containers?

后端 未结 10 2088
忘掉有多难
忘掉有多难 2020-11-27 09:31

Designing a new system from scratch. I\'ll be using the STL to store lists and maps of certain long-live objects.

Question: Should I ensure my objects have copy co

10条回答
  •  没有蜡笔的小新
    2020-11-27 10:16

    If you're storing polymporhic objects you always need to use a collection of base class pointers.

    That is if you plan on storing different derived types in your collection you must store pointers or get eaten by the slicing deamon.

提交回复
热议问题