列表矢量:任何人都知道如何做到这一点? [英] vector of lists: anyone know how to do this?

查看:67
本文介绍了列表矢量:任何人都知道如何做到这一点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将以下内容声明为向量 列表使用STL


vector<列表<边缘* GT; >


我已经尝试了很多方法来添加对象,但是无法弄清楚如何做到这一点。有没有人有任何提示,或者参考可能需要解释的材料?


任何帮助都非常感谢。

I''ve declared the following as a "vector" of "lists" using STL

vector< list<Edge*> >

I''ve tried many ways to add objects to this but can''t figure out how to
do it. Does anyone have any tips, or references to material that might
explain it?

Any help greatly appreciated.

推荐答案

craig写道:
craig wrote:
我已将以下内容声明为向量 列表使用STL

vector<列表<边缘* GT; >

我已经尝试了很多方法来添加对象,但是无法弄清楚如何做到这一点。有没有人有任何提示或参考可能解释它的材料?
I''ve declared the following as a "vector" of "lists" using STL

vector< list<Edge*> >

I''ve tried many ways to add objects to this but can''t figure out how
to do it. Does anyone have any tips, or references to material that
might explain it?




你决定隐藏我们代码的原因是什么?我们怎么能够确定你做错了什么?



Brian



And what is reason you decided to hide your code from us? How can we
figure out what you''re doing wrong?


Brian




craig写道:

craig wrote:
我已将以下内容声明为向量 列表使用STL

vector<列表<边缘* GT; >

我已经尝试了很多方法来添加对象,但是无法弄清楚如何做到这一点。有没有人有任何提示或参考可能解释它的材料?

任何帮助非常感谢。
I''ve declared the following as a "vector" of "lists" using STL

vector< list<Edge*> >

I''ve tried many ways to add objects to this but can''t figure out how to
do it. Does anyone have any tips, or references to material that might
explain it?

Any help greatly appreciated.




为什么不类似于:


Edge * pEdge = NULL;

vector<列表<边缘*> > edge(10);

edges [0] .push_back(pEdge);

将指针放入STL容器并不总是一个好主意。制作

确定你知道自己在做什么。


喜欢这样的东西:


提升: :shared_ptr的<边缘> pEdge;

vector<列表<升压:: shared_ptr的<边缘> > edge(10);

edges [0] .push_back(pEdge);


您选择的智能指针虽然取决于上下文,但

boost :: shared_ptr用于很多用途。 std :: auto_ptr不是

通常是一个不错的选择。

当然包括代码不起作用并告诉我们什么

您正在考虑可以帮助我们更好地回答。

K



Why not something like:

Edge *pEdge = NULL;
vector< list< Edge * > > edges( 10 );
edges[ 0 ].push_back( pEdge );
Putting pointers into STL containers is not always a good idea. Make
sure you know what you''re doing.

Prefer something like this:

boost::shared_ptr< Edge > pEdge;
vector< list< boost::shared_ptr< Edge > > edges( 10 );
edges[ 0 ].push_back( pEdge );

Your choice of smart pointer depends on context though, although
boost::shared_ptr is for many uses a good one. std::auto_ptr is not
normally a good choice.
Of course including the code that doesn''t work and telling us what
you''re thinking about might help us to answer better.
K


文章< 1150530822.539811.41420

@ i40g2000cwc.googlegroups.com>,
ki * ***************@gmail.com 说...


[...]
In article <1150530822.539811.41420
@i40g2000cwc.googlegroups.com>,
ki****************@gmail.com says...

[ ... ]
你选择的智能指针虽然取决于上下文,尽管
boost :: shared_ptr适用于很多用途。 std :: auto_ptr通常不是一个好的选择。
Your choice of smart pointer depends on context though, although
boost::shared_ptr is for many uses a good one. std::auto_ptr is not
normally a good choice.




让我更强烈地说。你在

标准容器中存储的任何东西都需要是可复制的,并且

std :: auto_ptr是不可复制的,所以根本不允许这样做。 />
在大多数情况下,如果你尝试编译将失败,但是

错误信息很少会使

问题的来源非常清楚。


-

后来,

杰瑞。


宇宙是一个想象自己的想象力。



Let me put that more strongly. Anything you store in a
standard container needs to be copyable, and
std::auto_ptr isn''t copyable, so it''s simply not allowed.
In most cases, compilation will fail if you try, though
the error message(s) rarely make the source of the
problem very clear.

--
Later,
Jerry.

The universe is a figment of its own imagination.


这篇关于列表矢量:任何人都知道如何做到这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆