开发者

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)).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜