Boost logo

Boost Users :

Subject: Re: [Boost-users] bind member function of a member of a class...
From: Kevin Ludwig (kevin.ludwig_at_[hidden])
Date: 2009-03-04 17:46:14


I'm still a novice with bind but I think you have to bind twice:

#include <iostream>
#include <functional>
#include <algorithm>

#include <boost/bind.hpp>
using std::cout;
using std::endl;
using std::equal_to;

class A
{
 int i_;
public:
 int test() {return i_;}
};

class B
{
  A _a;
public:
  A& getA() {return _a;}
};

int main()
{
    B b;

    cout << (1 == boost::bind(&A::test,
            boost::bind(&B::getA, &b))()) << endl;
    return 0;
}

On Wed, Mar 4, 2009 at 2:33 PM, Archie14 <admin_at_[hidden]> wrote:

> I cannot figure out how to use boost::bind in following scenario:
>
> class A
> {
> int i_;
> public:
> int test() {return i;}
> };
>
> class B
> {
> A _a;
> public:
> A& getA() {return _a;}
> }
>
> bool testbind()
> {
> B b;
>
> // here I am trying to find out if b.getA().test() equals 1
> // I understand that B::getA::test is incorrect, and that's my question-
> // how to use bind here?
> return (boost::bind (&B::getA::test, b) ==1);
> }
>
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Kevin


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net