a question about "bind2nd" ?

F

flyaflya

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?
 
A

Andre Kostur

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()"
 
T

Thomas Maier-Komor

flyaflya said:
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 ) );
 

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,821
Latest member
AleidaSchi

Latest Threads

Top