Cannot convert from one iterator type to another but both are the exact same
Asked Answered
P

1

8

I'm attempting to compile the ZipStream library, it is effectivley a C++ wrapper for zlib.

Right now I'm at the point where I'm getting two compile errors on these two lines:

std::set<file_info_32*, sort_by_offset>::iterator first  = _core->_entries_by_name.begin();
std::set<file_info_32*, sort_by_offset>::iterator last   = _core->_entries_by_name.end();

The errors are:

Error 15 error C2440: 'initializing' : cannot convert from
'std::_Tree_const_iterator<_Mytree>' to
'std::_Tree_const_iterator<_Mytree>' c:\users\ahakeem\desktop\zipstream\ziparchive.cpp 423 1 zipstream
Error 16 error C2440: 'initializing' : cannot convert from
'std::_Tree_const_iterator<_Mytree>' to
'std::_Tree_const_iterator<_Mytree>' c:\users\ahakeem\desktop\zipstream\ziparchive.cpp 424 1 zipstream

So basically the compiler says it can't convert from 'std::_Tree_const_iterator<_Mytree>' to 'std::_Tree_const_iterator<_Mytree>'

Any ideas why it's happening and how to fix?

edit: after further investigating I've found that _core->entries_by_name.begin() is declared as 'std::set<file_info_32*, sort_by_offset>', which is obviously inconsistant with what its iterator is trying to be assigned to (std::set<file_info_32*, sort_by_offset>).

Switching it to _core->_entries_by_offset.begin(); works because _entries_by_offset is a type consistant with what the assignee is expecting to get.

Does this mean someone may have broken the code, didn't realize it and uploaded it to the source repo? Or can this scenario of erraneous assignment actually compile on some systems?

Perl answered 28/11, 2011 at 23:46 Comment(5)
Const correctness? See if you can find something that's erroneously non-const.Unlock
or they are different _MytreesIntramolecular
@ildjarn Im certain i didn't paste the wrong errors, those are the two compile errors I get when I compile, I've added more to my question if it makes a difference.Perl
you might have an outdated compiler/library, so it doesn't know that iterator and const_iterator are constant iterators, and/or it doesn't provide conversions.Wesle
@Gene : VC++ 2010's standard library implementation is pretty solid, so I don't think that's pertinent here, but good advice in general.Ixtle
D
4

My best guess, the classes substituted for _MyTree are different.

Look for with _MyTree = SomeClass somewhere in your output just below the error.

Dempsey answered 29/11, 2011 at 2:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.