nabulke
nabulke

Reputation: 11285

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.begin(), 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;
};

Upvotes: 2

Views: 513

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136525

Correct expression is bind(&CInner::GetTemp, bind(&COuter::innerClass, _1)).

Upvotes: 3

Related Questions