0

I have a class like so:

class A {
    std::vector<
        std::vector<
            std::pair<
                uint32_t, std::reference_wrapper<std::vector<uint8_t>>>>>
        table;
};

In the constructor of the class I resize the vector, like so table.resize(indexSize)

but when I try to push items in I get an error:

void A::insertItem(const uint32_t &g, const vector<uint8_t> &point)
{
    this->table[g % this->indexSize].push_back(make_pair(g, point));
}

I guess when I resize I need to pass a constructor of some sort?

The error I get is:

no instance of overloaded function "std::vector<_Tp, _Alloc>::push_back [with _Tp=std::pair<uint32_t, std::reference_wrapper<std::vector<uint8_t, std::allocator<uint8_t>>>>, _Alloc=std::allocator<std::pair<uint32_t, std::reference_wrapper<std::vector<uint8_t, std::allocator<uint8_t>>>>>]" matches the argument list -- argument types are: (std::pair<uint32_t, std::vector<uint8_t, std::allocator<uint8_t>>>) -- object type is: std::vector<std::pair<uint32_t, std::reference_wrapper<std::vector<uint8_t, std::allocator<uint8_t>>>>, std::allocator<std::pair<uint32_t, std::reference_wrapper<std::vector<uint8_t, std::allocator<uint8_t>>>>>>

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Fotiadis M.
  • 95
  • 1
  • 12
  • 1
    What error do you get? Also please post a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – MikeCAT Oct 16 '20 at 12:35
  • @MikeCAT just added the error, for a Reproducible Example, it's literally just the stuff I have posted plus the constructor where I do the table.resize( /*with given indexSize*/). – Fotiadis M. Oct 16 '20 at 12:43

1 Answers1

1

This example is functional:

#include <vector>
#include <functional>

int main(int, const char**) {
    std::vector<uint8_t> abc = {5, 6};
    std::vector<
        std::vector<
            std::pair<uint32_t, std::reference_wrapper<std::vector<uint8_t>>>
            >
        > table;
    table[0].push_back(std::make_pair(4, std::reference_wrapper<std::vector<uint8_t>>(abc)));
    return 0;
}

The second argument of your pair have a constructor that needs an argument.

Dayrion
  • 23
  • 3