【发布时间】:2019-10-17 18:38:59
【问题描述】:
如果我有一个共享指针向量 (V1) 和一个包含大量字符串 (V2) 的向量。如何使用 V1 内部的 shared_ptr 指向 V2 内部的元素?
前:
std::vector< std::shared_ptr< SImplementation > > V1;
std::vector < std::string > V2; // there are strings in the V2 already
for(auto i : V2){
V1.push_back(i) // I tried this way, but it does not work because of the different types, different types mean int, string, unsigned long
}
我可以使用迭代器或使用另一个 shared_pointer 来指向 V2 中的字符串吗?
【问题讨论】:
-
本例中的
type是什么? -
指针,无论智能与否,都不是容器。你真正想做什么?你想解决什么问题?您是否想要一个指向
V2中元素的指针向量?为什么?同样,您需要解决的问题(真正的和原始的问题)是什么? -
指向什么的共享指针向量?
-
V1 甚至不是向量
-
@HuangMolly:请提供MVCE。现在你让人们猜测你想要实现什么。
标签: c++ vector iterator shared-ptr