Hi all.
I've been using boost::bind to work around deficiencies with
std::mem_fun_ref and std::bind2nd under MSVC6.
I have a class called CDocumentAttachments which had a member
function thus:
HINSTANCE Execute(LPCTSTR verb) const;
I was using bind with this as follows:
for_each(filenames.begin(),
filenames.end(),
bind(&CDocumentAttachments::Execute, _1, _T("print")));
"filenames" is a const vector of CDocumentAttachments objects.
This worked fine.
A little later on in development, I changed the function signature for
CDocumentAttachments::Execute to:
HINSTANCE Execute(LPCTSTR verb, bool visible) const;
How will I pass the extra bool to bind? I can't find any examples of
passing more than one parameter to a member function.
I thought about (among many others)
for_each(filenames.begin(),
filenames.end(),
bind(&CDocumentAttachments::Execute, _2, _T("print"),
false));
but the compiler (VC6) complains with two of the following:
k:\vc\include\boost\bind.hpp(760) : error C2679: binary '[' : no
operator
defined which takes a right-hand operand of type 'const class
boost::arg<2>'
(or there is no acceptable conversion)
k:\vc\include\boost\bind\bind_template.hpp(33) : see
reference to
function template instantiation 'struct HINSTANCE__ *__cdecl
boost::_bi::evaluator3
Paul Thompson wrote:
I thought about (among many others)
for_each(filenames.begin(), filenames.end(), bind(&CDocumentAttachments::Execute, _2, _T("print"), false));
Looks good to me, but why have you changed _1 to _2? The parameter you are passing in this place is the same (pointer to your objects as found by dereferencing the iterator) If you change _2 to _1 I think it should work. -- AlisdairM
--- In Boost-Users@yahoogroups.com, Alisdair Meredith
Paul Thompson wrote:
I thought about (among many others)
for_each(filenames.begin(), filenames.end(), bind(&CDocumentAttachments::Execute, _2, _T("print"), false));
Looks good to me, but why have you changed _1 to _2? The parameter you are passing in this place is the same (pointer to your objects as found by dereferencing the iterator)
If you change _2 to _1 I think it should work.
Yeah, I tried that, but I got 39 errors! Hence playing with the placeholder - it got fewer errors. Sounds daft, I know. I don't have the code with me here. I'll try some more when I get to work tomorrow. Thanks for your time! Paul
--- In Boost-Users@yahoogroups.com, Alisdair Meredith
wrote: Paul Thompson wrote:
I thought about (among many others)
for_each(filenames.begin(), filenames.end(), bind(&CDocumentAttachments::Execute, _2, _T ("print"), false));
Looks good to me, but why have you changed _1 to _2? The
--- In Boost-Users@yahoogroups.com, "Paul Thompson"
are passing in this place is the same (pointer to your objects as found by dereferencing the iterator)
If you change _2 to _1 I think it should work.
Yeah, I tried that, but I got 39 errors! Hence playing with the placeholder - it got fewer errors. Sounds daft, I know.
I don't have the code with me here. I'll try some more when I get to work tomorrow.
Yes, it works fine now (using _1). I can't think what I must have tried before. Blame it on the beer. Thanks to you guys for your help. Paul
participants (2)
-
Alisdair Meredith
-
Paul Thompson