str*_*obe 18 c++ templates typedef function-pointers
我想为函数指针创建typedef,其中stl容器作为参数,并且此容器具有未知类型.像这样的东西:
typedef void (* TouchCallBack)(GLRenderer*, const MotionEvent&, std::vector<T >);
Run Code Online (Sandbox Code Playgroud)
这是可能的?(特别是在c ++ 03中)
chr*_*ris 33
我不知道任何C++ 03解决方案与此类似,并且它不是内置于该语言中,但在C++ 11中,这可能是using别名:
template<typename T>
using TouchCallBack = void (*)(GLRenderer*, const MotionEvent&, std::vector<T >);
Run Code Online (Sandbox Code Playgroud)
C++ 03的一个解决方法是使用结构:
template<typename T>
struct TouchCallBack {
typedef void (*type)(GLRenderer*, const MotionEvent&, std::vector<T >);
};
//use like TouchCallBack<int>::type
Run Code Online (Sandbox Code Playgroud)