Reputation: 526
I have the following code that works in Visual Studio 10 and I want to port it on Linux -> GCC:
parse( v, srcUtf8.begin(), srcUtf8.end() ); <-- ERROR
picojson.h
template <typename Iter> inline std::string parse(value& out, Iter& pos, const Iter& last)
{
...
}
I get this error:
error: no matching function for call to ‘parse(picojson::value&, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >)’
note: candidates are: std::string picojson::parse(picojson::value&, Iter&, const Iter&) [with Iter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]
Could I get please some help on this ?
Upvotes: 3
Views: 281
Reputation: 311058
The problem is that function parse
has the second parameters of type Iter& pos
that is a non-constant reference
template <typename Iter> inline std::string parse(value& out, Iter& pos, const Iter& last)
You may not bind a non-const reference to temporary object srcUtf8.begin()
Try the following
auto it = srcUtf8.begin();
parse( v, it, srcUtf8.end() );
Or instead of the type specifier auto
write the explicit type of the iterator. For example if it is an iterator of class std::string then
std::string::iterator it = srcUtf8.begin();
parse( v, it, srcUtf8.end() );
Or if srcUtf8 is a constant object then
std::string::const_iterator it = srcUtf8.begin();
parse( v, it, srcUtf8.end() );
As for the MS VC++ 2010 then it has many bugs or its own language extensions that do not satisfy the C++ Standard.
Upvotes: 2