Element* (*) (int, Domain*)
is for function pointers. These are of two types.
- Raw function pointers (which is something like this:
void (*foo)(int x, int y);
).
- Member function pointers (which looks something like this:
void (Object::*foo)(int x, int y);
).
In a raw function pointer, its made of 3 parts. Lets use the above example,
- Return type (which is
void
).
- Function name/ pointer name (which is
foo
).
- Function parameters (which is
(int x, int y)
).
In a member function pointer, its made of 4 parts.
- Return type (which is
void
).
- Which class/ struct holds the function (which is
Object
).
- Function name/ pointer name (which is
foo
).
- Function parameters (which is
(int x, int y)
).
Calling a raw function pointer is as easy as this,
void Func(int x, int y) { ... }
void (*foo)(int x, int y) = Foo; // Assigning the function pointer.
foo(); // Calling the pointer.
Calling a member function pointer is slightly different. For this you need a valid instance of the object.
class Object {
public:
void Func(int x, int y) { ... }
};
void (Object::*foo)(int x, int y) = &Object::Func; // Assigning the function pointer. Notice the '&' operator here.
Object object;
(object.*foo)(); // Calling the function pointer.
So what map<int, Element* (*) (int, Domain*) > elemList
does is, it stores a map of raw function pointers which is mapped to an integer.
Additional: In order to assign a function to a function pointer, these things should match,
- The return type.
- Parameters of the function.
- The object which holds the function (this is only for member functions).