简体   繁体   English

错误:呼叫C ++没有匹配功能

[英]Error: no matching function for call C++

I am new to C++. 我是C ++的新手。 I have implemented a B+ tree and it is working fine on Macbook (with CLion) but when I run it on a ubuntu server it gives the compilation error below. 我已经实现了一个B +树,它在Macbook(带有CLion)上可以正常工作,但是当我在ubuntu服务器上运行它时,下面给出了编译错误。 Can someone help with this please? 有人可以帮忙吗?

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)’

Result of g++ -v on Mac: 在Mac上g ++ -v的结果:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 9.0.0 (clang-900.0.38) Target: x86_64-apple-darwin16.7.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin 配置为:--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 InstalledDir:/ Library / Developer / CommandLineTools / usr / bin

Result of g++ -v on ubuntu server: g ++ -v在ubuntu服务器上的结果:

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

Code snippet where error is thrown: 引发错误的代码段:

    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...
}

Constructing a std::vector with iterators requires them to be the same type. 使用迭代器构造std::vector要求它们具有相同的类型。 It looks like you're constructing it with a vector<>::const_iterator and a vector<>::iterator (via .end() ). 看起来您正在使用vector<>::const_iteratorvector<>::iterator (通过.end() )构造它。

Either make old_dn_values_end a non-const iterator or use .cend() . old_dn_values_end非常量迭代器,或使用.cend()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM