c++ boost::bind::binding_member_function














































c++ boost::bind::binding_member_function



DESCRIPTION-:

BOOST.BIND  is one of those boost library which makes it easier to understand the std::bind() function. 
                                                                     OR
BOOST.BIND is an alternative simplified  approch to use  std::bind().

*This boost library contain header file as #include<boost/bind.hpp> which mainly contain boost::bind(function_name,parameter_1,parameter_2......parameter_n)  
as its function template.

Here boost bind is used to bind a member function of a class.The syntax used here is

boost::bind(&class_name::function_name,&obj,arg_1,arg_2,....arg_n);
__________________________________________________________________________________________________
PROGRAM-


#include<iostream.h>
#include<boost/bind.hpp>  /*contain boost library*/

using namespace std ;
 

class example
{ public:
void  add(int a,int b)       /*declearing a member function*/
{
  cout<<a+b<<"\n";
}
};

int main()
{
     example e1,e2; 
int  a=boost::bind(&example::add,&e1,10,20);   
/*using boost bind that takes parameter by value to member function of a class*/
     int b=boost::bind(&example::add,&e2,20,20);
          a();                                                 /*calling "add" function by using boost.bind */
          b();                                                              
     return(0);
}
__________________________________________________________________________________________________
OUTPUT-
30
40
__________________________________________________________________________________________________

Comments