Reputation: 170
I have the following two variables:
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...
And I am trying to copy one vector
from relations
into transactions
:
transactions[key1][key2].push_back(relations[key2][key3]));
But I find this error:
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);
Any idea of what's happening?
Upvotes: 1
Views: 494
Reputation: 42888
relations[key2][key3]
is a vector<uint64_t>
, and you're trying to add it to transactions[key1][key2]
which is a vector<uint64_t>
.
You can't add vector<uint64_t>
to a vector<uint64_t>
.
If you'd like to add the contents of the first vector
to the second one, you need to use std::vector::insert
:
auto& dst = transactions[key1][key2];
const auto& src = relations[key2][key3];
dst.insert(dst.end(), src.begin(), src.end());
Upvotes: 6