View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Pointers to overloaded functions [solved]

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1joanusdmentia  Members

Posted 11 November 2004 - 12:10 PM

What's the syntax for taking the pointer to an overloaded function?
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));
}


Thanks. [Edited by - joanusdmentia on November 11, 2004 6:48:49 PM]

"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

### #2joanusdmentia  Members

Posted 11 November 2004 - 12:16 PM

Nevermind, worked it out.
????? = (float(*)(float,int))&func

"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

### #3snk_kid  Members

Posted 11 November 2004 - 12:17 PM

for a reference to a function:

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

### #4joanusdmentia  Members

Posted 11 November 2004 - 12:19 PM

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)

"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

### #5snk_kid  Members

Posted 11 November 2004 - 12:22 PM

Quote:
 Original post by joanusdmentiaIs 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.

### #6joanusdmentia  Members

Posted 11 November 2004 - 12:26 PM

Yeah, that's actually how I figured out what the syntax would be in the first place [smile]

Thanks.

"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

### #7joanusdmentia  Members

Posted 11 November 2004 - 12:38 PM

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 'operatorglobal 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.

"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

### #8snk_kid  Members

Posted 11 November 2004 - 12:46 PM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.