Start New Discussion within our Software Development Community

Hey, this might be a stupid question, but I just looked into the code of one thing which I can't tell what it is, but you get the idea here:

static ChatCommand unbanCommandTable[] =
{
	{ "ip",        'm', &ChatHandler::HandleIPUnBanCommand,        "Deletes an address  from the IP ban table: <address>", NULL, 0, 0, 0 },
	{ "character", 'b', &ChatHandler::HandleUnBanCharacterCommand, "Unbans character x",                                         NULL, 0, 0, 0 },
	{ "account",   'z', &ChatHandler::HandleAccountUnbanCommand,   "Unbans account x.",                                        NULL, 0, 0, 0 },
	{ NULL,        '0', NULL,                                      "",                                         NULL, 0, 0, 0 }
};

There is a reference to function, I mean like I want to make similar system to the my little RPG like a hook system that I can like hook my own function to onCharacterMove or something like that, this is a bit sucky explanation I am sorry, but I guess someone knows what I mean :( I mean that I make a table where the hooks will be stored and the move function runs them from there ?

Well in the above, the "&function" syntax is a function pointer which you can Google for. And the "hooks" that you are talking about is, from what I understand of your explanation, what is commonly known as "callback functions" which is very heavily used, especially in C interfaced libraries (such as most APIs). Look up these terms and check back on this thread if you want further explanation. Also, function pointers are not very popular anymore in C++ (unless it is for legacy with a C library or interface) because "function objects" are much more convenient, look that up too.

This article has been dead for over six months. Start a new discussion instead.