Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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.

  • You cannot reply to this topic
7 replies to this topic

#1 joanusdmentia   Members   -  Reputation: 1060

Like
0Likes
Like

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

Sponsor:

#2 joanusdmentia   Members   -  Reputation: 1060

Like
1Likes
Like

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

#3 snk_kid   Members   -  Reputation: 1312

Like
0Likes
Like

Posted 11 November 2004 - 12:17 PM

for a reference to a function:


static_cast<void (&)(double, int)>(func)

or

static_cast<void (&)(float, int)>(func)


for pointer to function:


static_cast<void (*)(double, int)>(func)

or

static_cast<void (*)(float, int)>(func)


I would try the reference one first with boost::bind

#4 joanusdmentia   Members   -  Reputation: 1060

Like
0Likes
Like

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

#5 snk_kid   Members   -  Reputation: 1312

Like
0Likes
Like

Posted 11 November 2004 - 12:22 PM

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.

#6 joanusdmentia   Members   -  Reputation: 1060

Like
0Likes
Like

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

#7 joanusdmentia   Members   -  Reputation: 1060

Like
0Likes
Like

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

"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

#8 snk_kid   Members   -  Reputation: 1312

Like
0Likes
Like

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.



PARTNERS