Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,287 of 33,346    |
|    Pete Becker to Seungbeom Kim    |
|    Re: overload resolution and function poi    |
|    12 May 12 11:05:28    |
      From: pete@versatilecoding.com              On 2012-05-12 10:10:03 +0000, Seungbeom Kim said:              > On 2012-05-11 18:30, Pete Becker wrote:       >> On 2012-05-11 19:21:54 +0000, Marc said:       >>       >>> I have several overloads of a function, I have a set of arguments, and       >>> I would like to get a function pointer to the overload the compiler       >>> would pick if I called this function on these arguments. I am not       >>> interested in applying the function now, I just want to get that       >>> pointer.       >>>       >>> Is this possible? Or is anything vaguely similar possible?       >>       >> Use a cast to select from a set of overloaded functions:       >>       >> void f(int);       >> void f(double);       >>       >> typedef void (*f_of_double)(double);       >>       >> f_of_double fptr = (f_of_double)&f;       >>       >> The typedef isn't actually needed; I used it here to clarify what's       >> going on. Yes, the cast looks wierd, but that's the rule.       >       > You don't actually need the cast either, do you?       >       > void (*f_int)(int) = &f; // points to f(int)       > void (*f_double)(double) = &f; // points to f(double)              Good point. No, you don't need it if the left-hand side determines the       type. You do need it when it doesn't:              template |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca