gpt4 book ai didi

c++ - map 插入中没有匹配的成员函数

转载 作者:行者123 更新时间:2023-11-30 00:49:10 25 4
gpt4 key购买 nike

我有以下两个变量:

static vector<map<uint32_t,vector<uint64_t>>> relations;
static map<uint64_t,map<uint32_t,vector<uint64_t>>> transactions;

uint64_t key1;
uint32_t key2;
uint32_t key3;
// init keys...

我正在尝试从 relations 中复制一个 vectortransactions 中:

transactions[key1][key2].push_back(relations[key2][key3]));

但我发现这个错误:

main.cpp:175:26: error: no matching member function for call to 'push_back'
transactions[key1][key2].push_back(relations[key2][key3]));
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:700:36: note: candidate function not viable: no
known conversion from 'vector<uint64_t>' to 'const value_type' (aka 'const unsigned long long') for 1st argument
_LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:702:36: note: candidate function not viable: no
known conversion from 'vector<uint64_t>' to 'value_type' (aka 'unsigned long long') for 1st argument
_LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);

知道发生了什么吗?

最佳答案

relations[key2][key3]vector<uint64_t> ,并且您正在尝试将其添加到 transactions[key1][key2]这是 vector<uint64_t> .

您不能添加 vector<uint64_t>vector<uint64_t> .


如果您想添加第一个 vector内容对于第二个,你需要使用 std::vector::insert :

auto& dst = transactions[key1][key2];
const auto& src = relations[key2][key3];
dst.insert(dst.end(), src.begin(), src.end());

关于c++ - map 插入中没有匹配的成员函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29103801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com