void func(float, int);
void func(double, int);
void test()
{
std::vector<float> v1,v2;
std::transform(v1.begin(),v1.end(),v2.begin(),boost::bind(?????,_1,2));
}
Pointers to overloaded functions [solved]
What's the syntax for taking the pointer to an overloaded function?
Thanks.
[Edited by - joanusdmentia on November 11, 2004 6:48:49 PM]
for a reference to a function:
for pointer to function:
I would try the reference one first with boost::bind
static_cast<void (&)(double, int)>(func)orstatic_cast<void (&)(float, int)>(func)
for pointer to function:
static_cast<void (*)(double, int)>(func)orstatic_cast<void (*)(float, int)>(func)
I would try the reference one first with boost::bind
Is there any way to get it to resolve the correct overload automatically? The syntax is a bit nasty.
As in something similar to when the function isn't overloaded when you could just write boost::bind(func,_1,2)
As in something similar to when the function isn't overloaded when you could just write boost::bind(func,_1,2)
Quote:Original post by joanusdmentia
Is there any way to get it to resolve the correct overload automatically? The syntax is a bit nasty.
You can avoid the cast by creating a variable:
float (&func_ref)(float, int) = func;std::transform(v1.begin(), v1.end(), v2.begin(), boost::bind(func_ref,_1,2));
EDIT: You can make it abit cleaner with some typedef'ing.
Yeah, that's actually how I figured out what the syntax would be in the first place [smile]
Thanks.
Thanks.
float (&absref)(boost::math::quaternion<float> const &) = boost::math::abs;std::transform(v1.begin(),v1.end(),v2.begin(),boost::bind(absref,_1));
Interesting, the std::transform() line generates the following errors:
...\boost\bind.hpp(62): error C2825: 'F::result_type': cannot form a qualified name...\boost\bind.hpp(62): error C2039: 'result_type' : is not a member of 'operator``global namespace'''...\boost\bind.hpp(62): error C2146: syntax error : missing ';' before identifier 'type'...\boost\bind.hpp(62): error C2955: 'boost::_bi::type' : use of class template requires template argument list...\boost\bind.hpp(62): fatal error C1903: unable to recover from previous error(s); stopping compilation
It's nothing essential, just a little test I did. Am I doing something wrong with this? I find it odd that boost::bind wouldn't be able to handle the type, it's not that complex after all.
EDIT: Hmm, reference types don't want to work, it needs to be a pointer.
boost::bind doesn't like reference to functions (oh well worth a try, would have been nice), it has to be pointer to function instead, my bad.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement