I'm setting up a new project that includes a std::multimap
ideally made of defined structs.
I've tried make_pair()
and multimap.insert()
, and that hasn't worked so far.
My code basically is:
struct myStruct {
myStruct() {}
myStruct(const myStruct &other) : foo(other.foo), bar(other.bar) {}
Neighbor &operator=(const myStruct &other) {
if (this != &other) {
foo = other.foo;
bar = other.bar;
}
return *this;
}
string foo;
std::vector<int> bar;
};
std::multimap<myStruct, myStruct> myMultiMap;
myStruct myStruct1;
myStruct myStruct2;
m_neighborMap.insert(std::pair<myStruct, myStruct>{myStruct1, myStruct2});
However, when I compile my code, I get the following errors:
/Library/Developer/CommandLineTools/usr/include/c++/v1/__functional_base:55:21: error: invalid operands to binary expression ('const myStruct' and 'const myStruct')
candidate template ignored: could not match 'pair<type-parameter-0-0, type-parameter-0-1>' against 'const myStruct'
operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
Does anyone know how to properly initialize this pair of structs? Thanks!