C++: Vector of objects vs. vector of pointers to new objects?

前端 未结 4 1419
遥遥无期
遥遥无期 2020-12-13 00:33

I am seeking to improve my C++ skills by writing a sample software renderer. It takes objects consisting of points in a 3d space and maps them to a 2d viewport and draws cir

4条回答
  •  醉话见心
    2020-12-13 01:12

    Well, it depends on what you are trying to do with your vector.

    If you don't use pointers, then it is a copy of the object you pass in that gets put on the vector. If it is a simple object, and/or you don't want to bother with keeping track of the storage for them, this may be exactly what you want. If it is something complex, or very time-consuming to construct and destruct, you might prefer to do that work only once each and pass pointers into the vector.

提交回复
热议问题