X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f From: "David Hilsee" Newsgroups: comp.os.msdos.djgpp,comp.lang.c++ References: <3C624DA4 DOT CDAF6FC3 AT bigfoot DOT com> <3C62529F DOT D7F259FA AT bigfoot DOT com> <3C62708F DOT 18766A42 AT bigfoot DOT com> Subject: Re: Error with bind2nd() and ptr_fun() Lines: 36 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: Date: Thu, 07 Feb 2002 13:03:06 GMT NNTP-Posting-Host: 68.49.80.44 X-Complaints-To: abuse AT home DOT net X-Trace: news1.rdc1.md.home.com 1013086986 68.49.80.44 (Thu, 07 Feb 2002 05:03:06 PST) NNTP-Posting-Date: Thu, 07 Feb 2002 05:03:06 PST Organization: Excite AT Home - The Leader in Broadband http://home.com/faster To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > > We can see that function > void foo1 (AAA& a) {a.set_value (a.get_value() + 100);} > can be used in for_each () > > So, what about > void foo2 (AAA& a, int n) { a.set_value (a.get_value() + n); } ? > > Is there any way to do what I want to ? > Yes, but the easiest way might be re-implementing a binder: struct AddToAAA { int value; AddToAAA( int val ) : value(val){} void operator() (AAA& inst) const { inst.set_value (inst.get_value() + value); } }; for_each(vect.begin(), vect.end(), AddToAAA (200)); Untested, but it should work. You might be able to apply some templates to make the functor more reusable. For instance, it could take a predicate, so you can pass things like std::plus et al instead of hard-coding the adding operation. I can't think of anything easier than the above, offhand. Perhaps someone else will come along with a better idea. -- David Hilsee