jdl
jdl

Reputation: 6323

Need help understanding function pointer define in the following?

Not sure what to make of the following and how to use it? thx

class A;
typedef void (*CALLBACK)( A*, void* );

Upvotes: 0

Views: 78

Answers (3)

Eric Finn
Eric Finn

Reputation: 8995

It is a type definition defining the type CALLBACK as a function pointer to a function that returns void and takes an A* and a void* as parameters.

typedef void (*CALLBACK)(A*, void*);
void cb(A*, void*);
CALLBACK handler = cb;
...
A* obj = new A();
some_type data;
handler(obj, &data);

Upvotes: 1

Tudor
Tudor

Reputation: 62439

It's a pointer to a function returning void and taking an A* and a void* parameter. E.g.

void foo(A* a, void* v)
{
   ...
}

...

CALLBACK c = foo;

Upvotes: 1

Andrea Bergia
Andrea Bergia

Reputation: 5542

You are defining a pointer to a function that returns void and takes an A * followed by void *. Thus you could do

void f(A*, void*);
CALLBACK cbk = f;
// ...
A* a;
void *p;
cbk(a, p);

Upvotes: 1

Related Questions