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

后端 未结 10 2071
忘掉有多难
忘掉有多难 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:17

    Generally storing the objects directly in the STL container is best as it is simplest, most efficient, and is easiest for using the object.

    If your object itself has non-copyable syntax or is an abstract base type you will need to store pointers (easiest is to use shared_ptr)

提交回复
热议问题