现在我有几个容器类型,包括地图,并发容器等,到目前为止,所有功能都有相同的功能,只要删除.我拥有的DeleteContainer(std :: vector< T *& VecIn)函数只能在上面提到的向量上工作.有没有什么办法使其通用到足以在所有容器上工作?
解决方法 你已经有了一个有效的答案,只是为了提供一个替代方案,我相信你应该考虑使用 Boost Pointer Container,让它处理内存管理:EDIT: Thanks for all the answers,I wish I Could select more than one. To anybody who stumbles onto this question,read all the answers and not just the selected one as they all provIDe great info.
总结This library therefore provIDes
standard-like containers that are for
storing heap-allocated or cloned
objects (or in case of a map,the
mapped object must be a heap-allocated
or cloned object). For each of the standard containers there is a pointer container equivalent that takes ownership of the objects in an exception safe manner.
以上是内存溢出为你收集整理的c – 使用模板删除任何容器全部内容,希望文章能够帮你解决c – 使用模板删除任何容器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)