jeudi 19 septembre 2019

No matching call to std::find() but i have other find statements that do not cause error amd ive included

I am writing function for a school project parsing XML. I have included the header as well as have other std::find() that compile successfully.

Ive narrowed down the problem to a specific function but it will not compile although other find statements do compile just fine.

#include <iostream>
#include <iterator>
#include <string>
#include <cstring>
#include <sys/types.h>

#include <unistd.h>
#include <errno.h>
#include <vector>
#include <algorithm>
#include <ctype.h>
#include "XMLParser.hpp"

void parseEndTag(std::vector<char>& buffer, std::vector<char>& pc,int& depth)
{
    //parse End Tag
    std::vector<char>::iterator endpc = std::find(pc, buffer.end(), '>');

    if (endpc == buffer.end())
        std::exit(1);
    --depth;

    std::advance(pc, 2);
    std::vector<char>::iterator pnameend = std::find_if(pc, buffer.end(), [] (char c) { return std::isspace(c) || c == '>' || c == '/'; });

    if (pnameend == buffer.end())
        std::exit(1);

    const std::string qname(pc, pnameend);
    const auto colonpos = qname.find(':');
    const std::string prefix     = colonpos != std::string::npos ? qname.substr(0, colonpos) : std::string("");
    const std::string local_name = colonpos != std::string::npos ? qname.substr(colonpos + 1) : qname;
    pc = std::next(endpc);
}

the following lines are the culprit

std::vector<char>::iterator endpc = std::find(pc, buffer.end(), '>');

std::vector<char>::iterator pnameend = std::find_if(pc, buffer.end(), [] (char c) { return std::isspace(c) || c == '>' || c == '/'; });

But in other functions the same exact statement compiles eg...

void parseDeclaration(std::vector<char>& buffer, std::vector<char>::iterator& pc)
{
    // parse XML declaration
    std::vector<char>::iterator endpc = std::find(pc, buffer.end(), '>');

    if (endpc == buffer.end())
        std::exit(1);

    pc = std::next(endpc);
    pc = std::find_if_not(pc, buffer.end(), [] (char c) { return std::isspace(c); });
}

here is the error code im getting for the iterator line

error: no matching function for call to ‘find(std::vector<char>&, std::vector<char>::iterator, char)’                                                                                                                                                           std::vector<char>::iterator endpc = std::find(pc, buffer.end(), '>');                                                                                                                                                                                                                                                                              ^                                                                                                                                                                                                       In file included from /usr/include/c++/7/bits/locale_facets.h:48:0,                                                                                                                                                                                                                              from /usr/include/c++/7/bits/basic_ios.h:37,                                                                                                                                                                                                                                    from /usr/include/c++/7/ios:44,                                                                                                                                                                                                                                                 from /usr/include/c++/7/ostream:38,                                                                                                                                                                                                                                             from /usr/include/c++/7/iostream:39,                                                                                                                                                                                                                                            from XMLParser.cpp:1:                                                                                                                                                                                                                                          /usr/include/c++/7/bits/streambuf_iterator.h:369:5: note: candidate: template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT>                                                                                 >::__type std::find(std::istreambuf_iterator<_CharT>, std::istreambuf_iterator<_CharT>, const _CharT2&)
     find(istreambuf_iterator<_CharT> __first,                                                                                                                                                                                                                                       ^~~~                                                                                                                                                                                                                                                                       /usr/include/c++/7/bits/streambuf_iterator.h:369:5: note:   template argument deduction/substitution failed:                                                                                                                                                                    XMLParser.cpp:56:72: note:   ‘std::vector<char>’ is not derived from ‘std::istreambuf_iterator<_CharT>’                                                                                                                                                                              std::vector<char>::iterator endpc = std::find(pc, buffer.end(), '>');                                                                                                                                                                                                                                                                              ^                                                                                                                                                                                                       In file included from /usr/include/c++/7/algorithm:62:0,                                                                                                                                                                                                                                         from XMLParser.cpp:10:                                                                                                                                                                                                                                         /usr/include/c++/7/bits/stl_algo.h:3899:5: note: candidate: template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)                                                                                                                                           find(_InputIterator __first, _InputIterator __last,                                                                                                                                                                                                                             ^~~~                                                                                                                                                                                                                                                                       /usr/include/c++/7/bits/stl_algo.h:3899:5: note:   template argument deduction/substitution failed:                                                                                                                                                                             XMLParser.cpp:56:72: note:   deduced conflicting types for parameter ‘_IIter’ (‘std::vector<char>’ and ‘__gnu_cxx::__normal_iterator<char*, std::vector<char> >’)                                                                                                                    std::vector<char>::iterator endpc = std::find(pc, buffer.end(), '>');

help would be appreciated and me and another student get the same problems even while working on this seperatly

Aucun commentaire:

Enregistrer un commentaire