I was wondering whether someone could help me fix this error. I've looked it over and can't see what possible is going wrong. The compiler is point to the line
while (_hasNextAttribute(it1, it2, thisAttribute))
of the following code
bool HtmlProcessor::_processTag(std::string::const_iterator it1, const std::string::const_iterator it2, node & nd)
{
/*
[it1, it2): iterators for the range of the string
nd: node in which classes and ids of the tage are stored
Returns true or false depending on whether a problem was encountered during the processing.
*/
std::string elementType("");
while (_elementTypeChars.find(*it1) != std::string::npos && it1 != it2) elementType.push_back(*it1++);
if (elementType.empty()) return false;
nd.element_type = elementType;
std::vector<std::pair<std::string, std::string>> attributes;
const std::pair<std::string, std::string> thisAttribute;
while (_hasNextAttribute(it1, it2, thisAttribute))
attributes.push_back(thisAttribute);
return true;
}
bool HtmlProcessor::_hasNextAttribute(std::string::iterator & it1, const std::string::iterator & it2, const std::pair<std::string, std::string> attrHolder)
{
....
and is saying
Non-const lvalue reference to type '_wrap_iter' cannot bind to a value of unrelated type '_wrap_iter'
When I try to compile your code, the compiler (VS 2013) complains const iterator it1
cannot be converted to std::string::iterator &
. The exact error message:
1>Cpp-Test.cpp(36): error C2664: 'bool _hasNextAttribute(std::_String_iterator>> &,const std::_String_iterator>> &,const std::pair)' : cannot convert argument 1 from 'std::_String_const_iterator>>' to 'std::_String_iterator>> &'
Basically you have two options:
Option 1: it1
and it2
are non-const
bool _processTag(std::string::iterator it1, const std::string::iterator it2, node & nd)
Option 2: _hasNextAttribute()
takes const iterators
bool _hasNextAttribute(std::string::const_iterator & it1, const std::string::const_iterator & it2, const std::pair<std::string, std::string> attrHolder)
Everything compiles fine for me when I apply one of these options (not both of course).
The choice is whether you want const iterators here. _hasNextAttribute()
looks like an info method to me, ie providing info, not changing anything. So I guess const iterator should be OK.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.