【发布时间】:2021-01-30 23:35:05
【问题描述】:
我有这样的课:
class A {
std::vector<
std::vector<
std::pair<
uint32_t, std::reference_wrapper<std::vector<uint8_t>>>>>
table;
};
在类的构造函数中,我调整了向量的大小,就像table.resize(indexSize)
但是当我尝试将项目推入时出现错误:
void A::insertItem(const uint32_t &g, const vector<uint8_t> &point)
{
this->table[g % this->indexSize].push_back(make_pair(g, point));
}
我想当我调整大小时,我需要传递某种构造函数?
我得到的错误是:
没有重载函数实例“std::vector<_tp _alloc>::push_back [with _Tp=std::pair
>>>, _Alloc=std::allocator<:pair std::reference_wrapper std::allocator>>>>>]" 匹配参数列表 --参数类型是: (std::pair >>) -- 对象类型是:std::vector<:pair std:: reference_wrapper std::allocator>>>>, std::allocator<:pair std::reference_wrapper std::allocator>>>>>>
【问题讨论】:
-
你得到什么错误?也请发Minimal, Reproducible Example。
-
@MikeCAT 刚刚添加了错误,对于一个可重现的示例,它实际上只是我发布的内容加上我执行 table.resize(/*with given indexSize*/) 的构造函数。跨度>
标签: c++ vector resize reference-wrapper