I have a batch of functions in a class:
class Edges // Edges of a Rubik's cube
{
// Stuff
protected:
// Edges movements
void e_U();
void e_D();
void e_F();
void e_B();
void e_R();
void e_L();
// More stuff
};
A new class inherits this functions:
class Cube: public Edges // Rubik's cube class
{
public:
void U(int); // U slice edges movement relative to spin
// Stuff
}
The call for the needed function depends on a number, as you see in the next code:
void Cube::U(int spin) // U slice movement for the given spin
{
switch (spin)
{
case 0: e_U(); return;
case 1: e_U(); return;
case 2: e_U(); return;
case 3: e_U(); return;
case 4: e_D(); return;
...
case 23: e_L(); return;
default: return;
}
}
I want to improve the performance, so I put the functions in an array:
class Cube: public Edges // Rubik's cube class
{
public:
void U(int); // U slice edges movement relative to spin
// Stuff
private:
const static void (*(USlice[24]))(); // U slice edges movement relative to spin
// More stuff
}
const void Cube::( (*(USlice[24]))() ) =
{
e_U, e_U, e_U, e_U,
e_D, e_D, e_D, e_D,
e_F, e_F, e_F, e_F,
e_B, e_B, e_B, e_B,
e_R, e_R, e_R, e_R,
e_L, e_L, e_L, e_L
};
So the U function should be now something like this:
void Cube::U(int spin) // U slice movement for the given spin
{
USlice[spin]();
}
My question is that I can't find the right way to declare the functions array inside the class. I've tried everything I can think of (remove "const" and "static" statements, make all public, ...)
The array should be "static" and "const", and the members are 24 "void" functions with no parameters.
Actually I don't know if declaring the functions in an array will be faster than using a switch statement, but I would like to check it.
Thanks.