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

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

    Using pointers will be more efficient since the containers will be only copying pointers around instead of full objects.

    There's some useful information here about STL containers and smart pointers:

    Why is it wrong to use std::auto_ptr<> with standard containers?

提交回复
热议问题