I need to initialize an interator by zero value. I tried following code
#include <map>
std::map<int, int>::iterator foo() {
std::map<int, int>::iterator ret;
ret = std::map<int, int>::iterator(0);
return ret;
}
It successfully compiled by gcc and intel C++ compilers on Linux. Also, this compiled well in minGW on Windows. The code provided with -O2 is
xorl eax, eax
ret
The issue is compilation under VisualStudio. The error is:
error C2440: '' : cannot convert from 'int' to 'std::_Tree_iterator>>> No constructor could take the source type, or constructor overload resolution was ambiguous.
Could you please give me an idea how to cast zero or rephrase initialization of iterator?
Thank you
PS
main idea is getting NULL at the end of the "list"
(it = a.begin(); it != a.end(); it = it->next)
that based on map::iterators from diffrent map objects.
a::end() {
return std::map<K, V>::iterator(0)
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…