By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,191 Members | 740 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,191 IT Pros & Developers. It's quick & easy.

a question about "bind2nd" ?

P: n/a
i use a class static member function to for_each:
class t1
{
static test(string s);
}

main()
{
list<string> slist;
...
for_each(slist.begin(), slist.end(), t1::test);
}
this can run, but when i give t1::test a parameter,like this :
class t1
{
static test2(string s, int 5);
}
main()
{
for_each(slist.begin(), slist.end(), bind2nd(t1::test2,5) ); //error !!!
for_each(slist.begin(), slist.end(), bind2nd(ptr_fun(t1::test2,5) ) );
//also error !!!
}

how to resolve this problem?

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
flyaflya wrote:
i use a class static member function to for_each:
class t1
{
static test(string s);
}

main()
{
list<string> slist;
...
for_each(slist.begin(), slist.end(), t1::test);
}
this can run, but when i give t1::test a parameter,like this :
class t1
{
static test2(string s, int 5);
}
main()
{
for_each(slist.begin(), slist.end(), bind2nd(t1::test2,5) ); //error !!!
for_each(slist.begin(), slist.end(), bind2nd(ptr_fun(t1::test2,5) ) );
//also error !!!
}

how to resolve this problem?


for_each(slist.begin(), slist.end(), bind2nd(ptr_fun(t1::test2),5 ) );
Jul 23 '05 #2

P: n/a
"flyaflya" <fl******@gmail.com> wrote in
news:d3**********@mail.cn99.com:
i use a class static member function to for_each:
class t1
{
static test(string s);
}

main()
{
list<string> slist;
...
for_each(slist.begin(), slist.end(), t1::test);
}
this can run, but when i give t1::test a parameter,like this :
class t1
{
static test2(string s, int 5);
}
main()
{
for_each(slist.begin(), slist.end(), bind2nd(t1::test2,5) );
//error !!!
for_each(slist.begin(), slist.end(),
bind2nd(ptr_fun(t1::test2,5) ) );
//also error !!!
}

how to resolve this problem?


First, post a short _compilable_ example of your problem. Use copy and
paste, don't attempt to type it in since you may make transcription
errors.

As an example, you don't give the 2nd parameter to test2 a name. And,
Standard C++ doesn't do default return values from functions, so a proper
declaration for main is "int main()"
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.