I need to have set as a class member variable, but also need it's comparision function object use the attributes of the class.
class Example
{
int _member1;
set<string, MyCmp> _myNameSet;
class MyCmp
{
Example& myEx;
MyCmp( const Example& ex) {
myEx = ex;
}
bool operator() (const string& lhs, const string& rhs)
{
/// Use "_member1" here ...
myEx._member1;
/// Do something ....
}
}
};
So here my question is, how do i pass the Example object as an argument to the MyCmp constructor? Since the "_myNameSet" is an member variable.
If it was not an member variable, there is a way i know:
void Example::functionBlah()
{
MyCmp obj(&(*this));
set<String, MyCmp> myLocalSet(obj);
}
You may use initializer list in constructor: