I'm working on some networking code. The first byte in a packet determines what kind of packet it is. For each kind of packet, there is a different handler function. These handler functions must be part of a certain class. For performance reasons, I don't want to use a huge switch statement, so I came up with this solution:
There is an array of function pointers. The array has 256 elements. When I recieve a packet, I use the first byte of the packet as the index on that array, and use it to call the appropriate function. This works with normal functions, but because some of the functions must change internal properties of the networking class (like the number of connected systems when a new system joins), they must be member functions.
When I try to create a pointer to a member function, I get the error " '&' : illegal operation on bound member function expression". I don't really understand what this means, could someone explain this to me in simple language?
I've tried to following ways:
internalPacketHandlers[i] = &(NetworkInterface::defaultPacketHandler);
internalPacketHandlers[i] = &(this.defaultPacketHandler);
internalPacketHandlers[i] = &defaultPacketHandler;
The last one works when defaultPacketHandler is a global function.
Thanks in advance