指向传染媒介元素的尖,当仍然增加时 [英] Pointer To A Vector Elements While Still Adding

查看:46
本文介绍了指向传染媒介元素的尖,当仍然增加时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有以下问题,如果

有人愿意提出有效的解决方案,我将非常感激它。


我创建一个A类实例,并且push_back将其复制到

向量V.这在迭代过程中重复多次。


每当我推回时A类的副本,我也想把一个包含在B类现有实例中的

指针分配给这个

特别新的push_back

向量V中的A类特定实例。当发生另一个push_back时我想要发生同样的事情,但是这个指针可能包含在另一个Class实例中A.


我担心因为新的

类的A实例更改而导致一个简单的指针变为

无效。


Adam

Hi All,

I have the following problem, and I would be extremely grateful if
somebody would be kind enough to suggest an efficient solution to it.

I create an instance of a Class A, and "push_back" a copy of this into a
vector V. This is repeated many times in an iterative process.

Ok whenever I "push_back" a copy of Class A, I also want to assign a
pointer contained in an exisiting instance of a Class B to this
particular newly "pushed_back" to a particular instance of Class A in
Vector V. When another push_back occurs I want the same to occur, but
this pointer might be contained in a different instance of Class A.

I am concerned because of the changing size of the vector due to new
instances of Class A been added might cause a simple pointer to become
invalid.

Adam

推荐答案

Adam Hartshorne写道:
Adam Hartshorne wrote:
我担心由于添加了A类的新实例而导致矢量大小发生变化可能会导致简单指针变得无效。
I am concerned because of the changing size of the vector due to new
instances of Class A been added might cause a simple pointer to become
invalid.



vector :: reserve()。

-

Ioannis Vranos

http://www23.brinkster.com/noicys


大家好,


我有以下问题,我想如果

有人会建议有效的解决方案,我将非常感激。


我创建一个A类实例,并且的push_back"将其复制到

向量V.这在迭代过程中重复多次。


每当我推回时A类的副本,我也想把一个包含在B类现有实例中的

指针分配给这个

特别新的push_back

向量V中的A类特定实例。当发生另一个push_back时我想要发生同样的事情,但是这个指针可能包含在另一个Class实例中A.


我担心因为新的

类的A实例更改而导致一个简单的指针变为

无效。


Adam
Hi All,

I have the following problem, and I would be extremely grateful if
somebody would be kind enough to suggest an efficient solution to it.

I create an instance of a Class A, and "push_back" a copy of this into a
vector V. This is repeated many times in an iterative process.

Ok whenever I "push_back" a copy of Class A, I also want to assign a
pointer contained in an exisiting instance of a Class B to this
particular newly "pushed_back" to a particular instance of Class A in
Vector V. When another push_back occurs I want the same to occur, but
this pointer might be contained in a different instance of Class A.

I am concerned because of the changing size of the vector due to new
instances of Class A been added might cause a simple pointer to become
invalid.

Adam
Ioannis Vranos写道:

vector :: reserve ()。
Ioannis Vranos wrote:

vector::reserve().




i认为你误解了我的问题。根据我的理解

reserve(),为向量中的n个元素保留空间。


我有什么指向向量中的元素,但是我担心

如果这是有效的,因为通过添加新的

元素来改变矢量的大小。


Adam



i think you have misunderstood my question. From what I understood
reserve(), reserves space for n elements in a vector.

I what to have pointers to the elements in the vector, but am concerned
if this is valid due to changing the size of the vector by adding new
elements.

Adam


2005-03-26,Adam Hartshorne<或******** @ yahoo.com>写道:
On 2005-03-26, Adam Hartshorne <or********@yahoo.com> wrote:
大家好,

我有以下问题,如果有人能够提出有效的解决方案,我将非常感激。

我创建了一个A类实例,并且push_back将其复制到一个
向量V.这在迭代过程中重复多次。

每当我推回时,都可以。 A类的副本,我也想把一个包含在B类现有实例中的指针分配给这个特别新的push_back指针。对于向量V中的A类的特定实例。当发生另一个push_back时,我希望发生同样的事情,但是这个指针可能包含在A类的不同实例中。
Hi All,

I have the following problem, and I would be extremely grateful if
somebody would be kind enough to suggest an efficient solution to it.

I create an instance of a Class A, and "push_back" a copy of this into a
vector V. This is repeated many times in an iterative process.

Ok whenever I "push_back" a copy of Class A, I also want to assign a
pointer contained in an exisiting instance of a Class B to this
particular newly "pushed_back" to a particular instance of Class A in
Vector V. When another push_back occurs I want the same to occur, but
this pointer might be contained in a different instance of Class A.

I am concerned because of the changing size of the vector due to new
instances of Class A been added might cause a simple pointer to become
invalid.



你有什么理由需要使用矢量吗?你的使用模式表明

另一个班级会更合适。


干杯,

-

Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord /


这篇关于指向传染媒介元素的尖,当仍然增加时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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