I am new to 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. 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:
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
Result of g++ -v on ubuntu server:
gcc version 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. It looks like you're constructing it with a vector<>::const_iterator
and a vector<>::iterator
(via .end()
).
Either make old_dn_values_end
a non-const iterator or use .cend()
.
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.