Map插入中没有匹配的成员函数

时间:2015-03-17 15:55:18

标签: c++

我有以下两个变量:

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

我正在尝试将vector中的一个relations复制到transactions

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

知道发生了什么?

1 个答案:

答案 0 :(得分:6)

relations[key2][key3]vector<uint64_t>,您尝试将其添加到transactions[key1][key2] vector<uint64_t>

您无法将vector<uint64_t>添加到vector<uint64_t>


如果您要将第一个vector内容添加到第二个{em>内容,则需要使用std::vector::insert

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