Boost logo

Boost Users :

From: Jaakko Jarvi (jajarvi_at_[hidden])
Date: 2002-08-27 10:22:02


> Oh, that works, thanks!
> To clarify though, for a member function, bind can be passed either
> an object pointer, an object reference, a function that returns an
> object pointer (the result of another bind), or a function that
> returns an object reference?
>

Yes, here are some of the cases:

#include "boost/lambda/bind.hpp"
#include "boost/lambda/lambda.hpp"

#include <iostream>

using namespace boost;
using namespace boost::lambda;

class Controller {
public:
  void DoSomething() { std::cout << "Hello World!"; };
};

class View {
  Controller& contr;
public:
  View(Controller& c) : contr(c) {};
  Controller& GetController() { return contr; }
  Controller* GetControllerPtr() { return &contr; }
};

int main () {

  Controller c;
  View v(c);
  View* vp = &v;
  
  bind(&Controller::DoSomething,
    bind(&View::GetController, _1))(v);

  bind(&Controller::DoSomething,
    bind(&View::GetController, _1))(vp);

  bind(&Controller::DoSomething,
    bind(&View::GetControllerPtr, _1))(vp);

};

// ------------------------

Cheers, Jaakko


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