I would like to make typedef for function pointer which has stl container as argument and this container has unknown type. Something like this:
typedef void (* TouchCallBack)(GLRenderer*, const MotionEvent&, std::vector<T >);
it's possible? (especially in c++ 03)
A typedef, or a function-type alias, helps to define pointers to executable code within memory. Simply put, a typedef can be used as a pointer that references a function.
In C++ this can be achieved using template parameters. A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function, template parameters allow to pass also types to a function.
typedef void (*MCB)(void); This is one of the areas where there is a significant difference between C, which does not - yet - require all functions to be prototyped before being defined or used, and C++, which does.
Function Pointer Syntaxvoid (*foo)( int ); In this example, foo is a pointer to a function taking one argument, an integer, and that returns void. It's as if you're declaring a function called "*foo", which takes an int and returns void; now, if *foo is a function, then foo must be a pointer to a function.
I don't know of any C++03 solution exactly like that, and it's not built into the language, but in C++11, this is possible with using
aliases:
template<typename T>
using TouchCallBack = void (*)(GLRenderer*, const MotionEvent&, std::vector<T >);
One workaround for C++03 is using a struct:
template<typename T>
struct TouchCallBack {
typedef void (*type)(GLRenderer*, const MotionEvent&, std::vector<T >);
};
//use like TouchCallBack<int>::type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With