Reputation: 4536
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?
Upvotes: 0
Views: 103
Reputation: 36487
Using objects (instead of pointers) requires that you name a second template parameter for std::set
used to compare two objects of pairT
. See std::less<>
for an example.
Also, what you're trying here seems to be wrong. You're trying to return a std::set
in CartesianProduct()
, but the returned PairCmp()
returns an integer.
Upvotes: 1