Using boost bind to access member function of inner class
I'm trying to access a member function of a nested class in a find_if expression.
My code below causes a compile error in the bind expression - (‘COuter::innerClass’ is not a class or namespace).
Could you help me with the correct bind expression?
vector<COuter> vec;
vec.push_back(COuter());
vector<COuter>::const_iterator it =
find_if(vec.b开发者_如何转开发egin(), vec.end(), bind(&COuter::innerClass::GetTemp, _1) == 42);
My example classes:
class CInner
{
public:
CInner() : _temp(42) {};
int GetTemp() const
{
return _temp;
}
private:
int _temp;
};
class COuter
{
public:
CInner innerClass;
};
Correct expression is bind(&CInner::GetTemp, bind(&COuter::innerClass, _1))
.
精彩评论