Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 507
meds Avatar asked Nov 28 '11 23:11

meds


1 Answers

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

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

like image 65
Michael Price Avatar answered Sep 28 '22 06:09

Michael Price