Error: no matching function for call C++

Error: no matching function for call C++

我是 C++ 新手。我已经实现了一个 B+ 树,它在 Macbook(使用 CLion)上运行良好,但是当我在 ubuntu 服务器上 运行 它时,它给出了下面的编译错误。有人可以帮忙吗?

error: no matching function for call to 
‘std::vector<std::__cxx11::basic_string<char> 
>::vector(__gnu_cxx::__normal_iterator<const 
std::__cxx11::basic_string<char>*, 
std::vector<std::__cxx11::basic_string<char> > >, 
std::vector<std::__cxx11::basic_string<char> >::iterator)’

g++ -v 在 Mac 上的结果:

配置为:--prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM 版本 9.0.0 (clang-900.0.38) 目标:x86_64-apple-darwin16.7.0 线程模型:posix 安装目录:/Library/Developer/CommandLineTools/usr/bin

ubuntu 服务器上 g++ -v 的结果:

gcc 版本 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)

抛出错误的代码片段:

    std::pair<InternalNode *, Node *> split(int order) {
    std::vector<float>::const_iterator old_dn_keys_end = keys.begin() + ceil(float(order) / 2) - 2;
    std::vector<std::string>::const_iterator old_dn_values_end = values.begin() + ceil(float(order) / 2) - 2;
    new_dn->keys = std::vector<float>(old_dn_keys_end + 1, keys.end());

   //**--- error here ---**
   new_dn->values = std::vector<std::string>(old_dn_values_end + 1, 
   values.end());
   //rest of the code...
}

用迭代器构建 std::vector 要求它们是同一类型。看起来您正在使用 vector<>::const_iteratorvector<>::iterator(通过 .end())构建它。

使 old_dn_values_end 成为非常量迭代器或使用 .cend().