Sign in to follow this  

(c++)whats wrong with this std::vector::insert() call?

This topic is 4203 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey I can't work out whats wrong with this insert call:
vector<Vertex> lineVertices;
//
vector<Vertex> vertices;
//
//append lineVertices onto vertices
vertices.insert(lineVertices.begin(), lineVertices.end());


It returns the error:
Quote:
error C2664: 'std::_Vector_iterator<_Ty,_Alloc> std::vector<_Ty>::insert(std::_Vector_iterator<_Ty,_Alloc>,const _Ty &)' : cannot convert parameter 2 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'const Vertex &' with [ _Ty=Vertex, _Alloc=std::allocator<Vertex> ] Reason: cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'const Vertex' with [ _Ty=Vertex, _Alloc=std::allocator<Vertex> ] No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
I don't understand what is wrong, I've done the exact same code before when using sets. thx

Share this post


Link to post
Share on other sites
When you use insert() with a std::vector, you need to specify the insertion point. Ex:

vertices.insert(vertices.begin(), lineVertices.begin(), lineVertices.end());

Share this post


Link to post
Share on other sites
edit: Too slow. Pwnd by 500.13 errors :'(

The form of insert() that you are using is taking two vector<>::iterator parameters/ There are 3 possible insert:

// iterator is vector<Type>::iterator
iterator insert(
iterator _Where,
const Type& _Val
);
// iterator is vector<Type>::iterator
void insert(
iterator _Where,
size_type _Count,
const Type& _Val
);
// iterator is vector<Type>::iterator
// InputIterator is any iterator type
template<class InputIterator>
void insert(
iterator _Where,
InputIterator _First,
InputIterator _Last
);

Thus, what you need is not

vertices.insert(lineVertices.begin(), lineVertices.end());

But

vertices.insert(vertices.begin(), lineVertices.begin(), lineVertices.end());


HTH

Share this post


Link to post
Share on other sites

This topic is 4203 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this