Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 86,269 C++ Programmers. There are 1,872 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a C++ Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

compiler error for iterators

 
Reply to this topicStart new topic

compiler error for iterators, type conversion?

mattman059
post 7 May, 2008 - 07:14 PM
Post #1


D.I.C Regular

Group Icon
Joined: 23 Oct, 2006
Posts: 295



CODE
vector<int>::iterator start  = myVector.begin();


When I try to compile this i get Error C2440 which is a "Type conversion" error, but what I dont understand is the actual description of the error

"Cannot Convert from
std::_Vector_iterator<_Ty,_Alloc> TO
std::_Vector_iterator<_Ty,_Alloc>"


To me it seems like there should be no problem running that code, intuitively it should work unless there are problems with iterators and vectors..
any thoughts.

This post has been edited by mattman059: 7 May, 2008 - 07:15 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


skaoth
post 7 May, 2008 - 11:03 PM
Post #2


D.I.C Regular

Group Icon
Joined: 7 Nov, 2007
Posts: 269

is it possible for you to provide more code? Not much to work with there.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

mattman059
post 8 May, 2008 - 07:23 AM
Post #3


D.I.C Regular

Group Icon
Joined: 23 Oct, 2006
Posts: 295

Well you see, the rest of the code works perfectly. I was thinking about it and it might have something to do with the two dimensional vector that I declared..

CODE
vector< vector<int> > myVector;


But other than that, if i take the previous line out of my code, it works perfectly
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

skaoth
post 8 May, 2008 - 10:39 AM
Post #4


D.I.C Regular

Group Icon
Joined: 7 Nov, 2007
Posts: 269

It sounds like you found your problem. I asked for more code because
I needed to see how you were declaring your vector object myVector.

As you found
CODE

    // 1) This is OK
    vector<int> v1;
    vector<int>::iterator v1Itr  = v1.begin();

    // 2) This is OK
    vector<vector<int>> v2;
    vector<vector<int>>::iterator v2Itr = v2.begin();
    
    // 3) This causes the error your are seeing
    v1 = v2.begin();


where you were getting the error, The template type
tells the iterator what the type is that will be held in the
vector. If your first case it was simply a type mismatch
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
Time is now: 5/16/08 10:31AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month