Question

static const Function* Get...();

Why can't I return pointer to a const from static member function? Or can I?

Where

typedef void Function(Object * object, HandlerAction action);

I just don't want to let caller to alter function pointer he got.

Was it helpful?

Solution

What you're trying to return in your code is a pointer to a constant non-member function (but this is not a valid construct, only member functions can be constant).

What you want to do is to return a constant pointer to a function, which would be written like this:

static Function * const Get...();

const always applies to the type to its immediate left; unless it's the first thing (which it is in your case, as static is no type and therefore cannot be made const - in that case it applies to the type to its immediate right, which is Function in your case, so the function type itself, not the pointer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top