C ++类的shared_ptr的向量

问题描述

正如标题所说,我想从一个类的shared_ptr声明一个向量。 这是班级成员。

类标题的声明:

std::vector<std::shared_ptr<connection>>RemoteVerbindungen;

在课程中的用法:

  RemoteVerbindungen.push_back(std::shared_ptr<connection>(new connection(SERVICE_SOCKET)));      
  //Iterator positionieren
  std::vector<std::shared_ptr<connection>>::iterator VerbindungsNr = RemoteVerbindungen.begin();

同样从类中,如果您使用迭代器或通过0直接访问,则对方法的访问不起作用。

RemoteVerbindungen[0]->startUp();
RemoteVerbindungen[VerbindungsNr]->startUp();

成员方法“ starUp”未执行。 不能通过迭代器访问“ RemoteConnections”向量。无法进行编译器错误类型转换。

我是否在指向指向新创建的“连接”类型对象的向量下创建新的ptr?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)