Overload operator overload type to point to a pointer to a function

I'm having difficulty overloading casting to a pointer to a class functional operator. In the code I want:

typedef int(*funcptrtype)(int);

struct castable {
   operator funcptrtype() {return NULL;}
};

but I want to do this without using typedef. If you're interested, I need this because pre-C ++ 11 template aliases are not available (so the trick is typedefnot an option in template contexts ...)

I usually expect this to work:

operator int(*)(int)() {return NULL;}

But this is not so. The compiler (g ++ 4.6.1) says:

error: ‘<invalid operator>’ declared as function returning a function

It works:

int (* operator()())(int){return 0;}

But you are actually overloading operator()to return a function pointer :)

The standard says:

The conversion type identifier must not be a function type or an array type

But it does not say the type of the function pointer (the first snipplet of the code works anyway ...).

- typedef?

+3
1

: , . typedef ; :

template<typename T>
struct something {
  typedef T (*type)(int);
};
+3

All Articles