English 中文(简体)
STL 克隆病媒
原标题:STL cloning a vector

!Hi I have a hard time trying to copy vector of pointers to Point. I have a

vector<Point*> oldVector

并且我要将这一病媒复制到其他病媒中。 因此,我使用了一台复印机。 我这样做了。

vector<Point*> newVector = vector<Point*>(oldVector.begin(),oldVector.end());

不幸的是,如果我行使这一职能,我就有一个例外。

vector interators incompatible

问题是什么?

EDIT There must be a bigger problem with iterators, it seems that I can t use iterators at all. I wanted to add two stl vectors into each other so I used wrote sth like this

 vector<int> a, b;
    b.insert(b.end(), a.begin(), a.end());

在执行这一条线时,我获得麦加特/市长。

“enterography

最佳回答

或者

vect或<Point*> *newVect或 = new vect或<Point*>(oldVect或.begin(),oldVect或.end());

vect或<Point*> newVect或(oldVect或.begin(),oldVect或.end());

When creating objects, you only use assignment when allocating from the heap. Otherwise, you simply place the construct或 argument(s) inside parentheses after your new variable name.

或者说,以下内容更为简单:

vect或<Point*> newVect或(oldVect或);
问题回答
vector<Point*> newVector = vector<Point*>(oldVector.begin(),oldVector.end());

为什么如此?

为什么不这样做:

vector<Point*> newVector(oldVector.begin(),oldVector.end());

? 后者越好!

更糟的是,

vector<Point*> newVector(oldVector);

由于原始集装箱的类型相同,std:vector<Point*>,没有必要使用范围构造者;简单使用复印件!

std::vector<Point*> newVector(oldVector);

但这并非主要关切。 这里的主要问题是共同点。 与拥有直线数据的人非常清楚。 注意双轨!

你们想要

Vector<Point*> newVector(oldVector.begin(), oldVector.end());

这一工作(以<条码>进行的合理测试:实验与设计;int>s)。 必须存在其他一些问题。 。 是否有复印件?





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签