如何用向量填充地图?
我有以下测试代码:
class Person{};
shared_ptr<Person> sp1;
shared_ptr<Person> sp2;
shared_ptr<Person> sp3;
vector<shared_ptr<Person>> members = {sp1,sp2,sp3};
map<string, shared_ptr<Person>> mymap;
如何将vector 成员
设置为mymap
的第二个元素?我尝试了和复制
的。
I have the following test code:
class Person{};
shared_ptr<Person> sp1;
shared_ptr<Person> sp2;
shared_ptr<Person> sp3;
vector<shared_ptr<Person>> members = {sp1,sp2,sp3};
map<string, shared_ptr<Person>> mymap;
How can I set the vector members
to the second element of mymap
? I tried with for
and copy
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MAP
是一个关联容器,因此您需要在String
中指定键将其关联到sharone_ptr&lt; person&gt;
。我不知道您需要什么,但是以下循环应该有效:map
is an associative container, so you need to specify the key instring
type to associate it to theshared_ptr<Person>
. I don't know what you need, but the following loop should work: