Is it possible to create a vector of pointers?

后端 未结 6 2352
情歌与酒
情歌与酒 2020-12-15 01:27

Just wondering, because of a problem I am running into, is it possible to create a vector of pointers? And if so, how? Specifically concerning using iterators and .begin()

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 01:55

    You have create vector for a vector of pointers. Then use new to allocate the memory for c objects and push them into vector. Also, don't forget that you have to delete yourself and vector.clear() will not release the memory allocated for c objects. You have to store c as a vector of pointers here, otherwise the call to the virtual function will not work.

提交回复
热议问题