如何定义具有模板参数的函数指针的typedef [英] How to define typedef of function pointer which has template arguments
本文介绍了如何定义具有模板参数的函数指针的typedef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为函数指针使用stl容器作为参数,并且此容器具有未知类型的typedef。类似这样:
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 >);
这可能吗? (特别是在c ++ 03中)
it's possible? (especially in c++ 03)
推荐答案
我不知道任何C ++ 03解决方案,但是在C ++ 11中,这可以用使用
别名:
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 >);
C ++ 03的一种解决方法是使用struct:
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
这篇关于如何定义具有模板参数的函数指针的typedef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文