EDIT: MOTIVATION
Suppose I define a Handler class as
class Handler { public: class Message { }; typedef int (*Callback)(Message *msg); void registerCallback(int msgclass, Callback f); };
Customer can perform
int f1(Handler::Message *msg) { } int f2(Handler::Message *msg) { } int main(){ Handler h; h.registerCallback(1, f1); h.registerCallback(2, f2);
The compiler does verify that f1 and f2 are appropriate parameters for registerCallback , however, for the client, correctly determine f1 and f2 . Since I haveready typedef ed Callback , I would like the client to be able to use it.
End edit
I would like to do something like this:
typedef int arithmetic(int i, int j); arithmetic sum { return i+j; } arithmetic max { return (i>j)? i:j; }
However both
arithmetic sum arithmetic sum()
not compiled as well as this
arithmetic sum(int i, int j)
which gives a compiler error
func.cpp: 4: error: 'sum is declared as a function returning a function
I want me to want a Handler class that provides a typedef for the callback function that it accepts , including a list of parameters .
c ++ syntax typedef function-pointers
davka
source share