aLLex aLLex - 2 months ago 24
C++ Question

C++ vector allocator error

I'm trying compile with gcc

#include <string>
#include <vector>

std::vector < std::string, std::vector < std::vector < int > > > plain;

int main(){
return 0;
}


But getting a error:
error: ‘class std::vector"<"std::__cxx11::basic_string, std::allocator"<"std::vector"<"int> > >’ has no member named ‘deallocate’

Answer

Your plain is std::vector<std::string, NotReallyAnAllocator> where NotReallyAnAllocator is std::vector < std::vector < int > >.

A std::vector (of anything) is not an allocator and the compiler clearly complains about the fact that it doesn't implement the necessary allocator interface.

I'm not sure what you wanted to achieve, but look into std::unordered_map and std::map if you need key-value containers.

Comments