home bbs files messages ]

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,284 of 33,346   
   Pete Becker to Marc   
   Re: overload resolution and function poi   
   11 May 12 18:30:57   
   
   From: pete@versatilecoding.com   
      
   On 2012-05-11 19:21:54 +0000, Marc said:   
      
   > Hello,   
   >   
   > 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.   
      
   --   
    Pete   
   Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The   
   Standard C++ Library Extensions: a Tutorial and Reference   
   (www.petebecker.com/tr1book)   
      
      
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca