boost::bind

S

STL-BOOST

Hi all:
how do i use bind for this:

struct fun
{
void exe()(int i){}
}

vector<fun> vec;
for_each(vec.begin(), vec.end(), ?);
 
M

Martin York

Hi all:
how do i use bind for this:

struct fun
{
void exe()(int i){}
}

vector<fun> vec;
for_each(vec.begin(), vec.end(), ?);


Do you really want fun::exe to return a pointer to a function?
I am assuming it is just a method that takes an int:


#include <vector>
#include <algorithm>
#include <functional>

struct XXfun
{
void exe(int i){}
};
struct YYfun
{
operator()(int x){}
};


int main()
{
std::vector<XXfun> vec;
std::for_each(vec.begin(), vec.end(),
std::bind2nd(std::mem_fun_ref(&XXfun::exe),1));

std::vector<YYfun> data;
YYfun yyFun;
std::for_each(vec.begin(), vec.end(), yyFun);
}
 
S

STL-BOOST

Do you really want fun::exe to return a pointer to a function?
I am assuming it is just a method that takes an int:

#include <vector>
#include <algorithm>
#include <functional>

struct XXfun
{
void exe(int i){}
};
struct YYfun
{
operator()(int x){}
};

int main()
{
std::vector<XXfun> vec;
std::for_each(vec.begin(), vec.end(),
std::bind2nd(std::mem_fun_ref(&XXfun::exe),1));

std::vector<YYfun> data;
YYfun yyFun;
std::for_each(vec.begin(), vec.end(), yyFun);



}- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -

but i want to use boost::bind, and how can i do
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top