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> Subject: Re: Error with bind2nd() and ptr_fun() Lines: 38 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 12:00:41 GMT NNTP-Posting-Host: 68.49.80.44 X-Complaints-To: abuse AT home DOT net X-Trace: news1.rdc1.md.home.com 1013083241 68.49.80.44 (Thu, 07 Feb 2002 04:00:41 PST) NNTP-Posting-Date: Thu, 07 Feb 2002 04:00:41 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 > Here is a program and compilation results. > > The compiler detects some error > and informs about "Internal compiler error". > > Is there an error in my program? > > for_each(vect.begin(), vect.end(), bind2nd(ptr_fun(foo2), 200)); // > Line#53 > d:/sys/djgpp/lang/cxx/stl_function.h: In instantiation of > `binder2nd >': > d:/sys/djgpp/lang/cxx/stl_function.h:231: instantiated from > `bind2nd, int>(const > pointer_to_binary_function &, const int &)' > aaa.c:53: instantiated from here > d:/sys/djgpp/lang/cxx/stl_function.h:223: forming reference to reference > type `AAA &const' This message pretty mch says it: you're forming a reference to a reference. The problem is that the binder that results from bind2nd tries to take the argument in its operator() (the first parameter of the function) by reference. That parameter, in your code, is already a reference, and that makes it try to generate a reference to a reference, which isn't allowed. Boost tries to overcome this, BTW, and has a brief section explaining references to references. http://www.boost.org/libs/functional/index.html -- David Hilsee