Give the comparator a constructor which accepts the argument to determine the comparator's behaviour:
struct sortset
{
sortset(const string& sortingVar) : sortingVar(sortingVar) {}
bool operator() (const string& s1, const string& s2) const {
//Sorting algorithm based on "sortingVar"
}
private:
const string sortingVar;
};
int main() {
string sortingVar; cin >> sortingVar;
// Either:
set<string, sortset> mySet{sortset{sortingVar}};
// Or:
sortset comp{sortingVar};
set<string, sortset> mySet{comp};
// ...
}
Notice that the set constructor allows you to provide an actual instance of the comparator, so you can use that to pass one that is not default-constructed (a good thing too, since no such thing can now exist).
Add some std::move
s if you like.
Don't forget to give main
a return type.