Hey all. I'm working on an implementation of a d20 character (think Dungeons and Dragons, but more general purpose), and for my implementation of feats, I've created a feat class, with a series of function pointers to represent events that feats might effect (getting skill bonuses, calculating crit damage, etc). Each instance then sets these to various functions.

Anywho, part of the code loops through an array of feats, and calls the particular "event" for each feat in the array. Anywho, this is obviously causing problems, as feats which don't set EVERY function-pointer are crashin the program. So, what I need is a way of testing whether a function-pointer is null/empty/unset.

Can anyone help me out??

A function pointer is still a pointer. If you set it to NULL or 0 it is a null pointer and then the test is easy:

for (int x = 0; x < nFeats; ++x)
{
    if (feats[x] != NULL) (*feats[x])();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.