steve@Pkg.Mcc.COM (Steve Madere) (08/28/90)
I need a way to get a pointer to one of a set of overloaded functions. I need to specify in the source code exactly which version of the function I need. eg: void print(char*); void print(int); void print(float); printmythingy(v,print,ser1); How do I specify that the print function that I want is the one that goes with the char* argument? Steve Madere
steve@taumet.com (Stephen Clamage) (08/28/90)
steve@Pkg.Mcc.COM (Steve Madere) writes: >I need a way to get a pointer to one of a set of overloaded functions. >void print(char*); >void print(int); >void print(float); >printmythingy(v,print,ser1); >How do I specify that the print function that I want is the one that goes >with the char* argument? The prototype for printmythingy must show the type of each argument. Each function of an overloaded set must have a different type. Thus you can't help but specify that at most one of any overloaded function set may be used. Example: void printmythingy(T1, void(*)(char*), T2); For the second argument, you may pass only a function returning void and having just one parameter of type char*. There is only one of the print functions having that type, so writing printmythingy(v,print,ser1); can only result in passing void print(char*); as the print function. -- Steve Clamage, TauMetric Corp, steve@taumet.com
steve@Pkg.Mcc.COM (Steve Madere) (08/29/90)
In article <424@taumet.com>, steve@taumet.com (Stephen Clamage) writes: | steve@Pkg.Mcc.COM (Steve Madere) writes: | | >I need a way to get a pointer to one of a set of overloaded functions. | | >void print(char*); | >void print(int); | >void print(float); | | >printmythingy(v,print,ser1); | | >How do I specify that the print function that I want is the one that goes | >with the char* argument? | | The prototype for printmythingy must show the type of each argument. | Each function of an overloaded set must have a different type. Thus | you can't help but specify that at most one of any overloaded function | set may be used. Example: | | void printmythingy(T1, void(*)(char*), T2); No, no, no. You're missing the whole point. I am creating a function vector table (list of conditions and the function that should be called when the condition is met). I need to install pointers to all sorts of functions into this list. So to be more specific: InstallAction("print",print); InstallAction("remove",remove); is closer to the call that I want to make. But I still want the version of print that takes a char* argument. All I really want is a pointer to this damned function. Isn't there a well defined way of doing this?
mjv@objects.mv.com (Michael J. Vilot) (09/03/90)
Steve Madere writes: > | void printmythingy(T1, void(*)(char*), T2); > > No, no, no. You're missing the whole point. > I need to install all sorts of functions. I'm afraid Steve Clamage is right -- the ``well-defined'' way to express pointers is to correctly state their type. His example does what you asked. If you have the need to install functions of different types, you can overload your InstallAction function to accepts the different types of functions. -- Mike Vilot, ObjectWare Inc, Nashua NH mjv@objects.mv.com (UUCP: ...!decvax!zinn!objects!mjv)