I’m getting a weird compiler error and as I’m new to using set’s with custom struct’s I’m not sure what exactly the problem is.
I’m trying to create a set of “pair’s” and am using a custom comparison function for inserting said pair’s.
struct pairT {
std::string first, second;
};
int PairCmp(pairT &one, pairT &two) {
if (one.first < two.first && one.second == two.second) return 0;
else if (one.first < two.first) return -1;
else if (one.first == two.first && one.second < two.second) return -1;
return 1;
}
std::set<pairT> CartesianProduct (std::set<std::string> &one, std::set<std::string> &two) {
std::set<pairT> returnSet(PairCmp);
/.../
I’m getting the error from the last line of code:
C2664 “can’t convert parameter 1 from int to const std::less… blah, blah, blah.
Any suggestions as to why I’m getting my ass kicked?
Using objects (instead of pointers) requires that you name a second template parameter for
std::setused to compare two objects ofpairT. Seestd::less<>for an example.Also, what you’re trying here seems to be wrong. You’re trying to return a
std::setinCartesianProduct(), but the returnedPairCmp()returns an integer.