C++为成员函数提供typedef模板的一种方法
C++ a way to have a typedef template to a member function?
标题几乎说明了一切!
有什么漂亮/简单的方法可以做到这一点吗?由于函数指针不能指向成员函数,并且成员函数需要知道成员所属的类,但在这种情况下,由于函数来自的类不同,因此没有此类信息。请只使用标准库!
template <class A>
typedef void (A::*Function)(Parameters p);
您可以尝试将其包装在这样的结构中:
template <class T>
struct method_ptr
{
typedef void (T::*Function)(Parameters p);
};
class A
{
public:
void foobar(Parameters);
};
// ...
method_ptr<A>::Function pfoobar = &A::foobar;
未测试,但这应该与C++11编译器一起使用:
template <typename T>
using Function = void (T::*)(Parameters p);
现在有趣的问题是,解决这个问题的问题是什么。
相关文章:
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 有没有一种方法可以在编译时获得作用域类名
- 对于C++中使用智能指针的指针算术限制,有没有一种变通方法
- 一种在C++中读取TXT配置文件的简单方法
- 有没有一种方法可以测量c++程序的运行时内存使用情况
- 有没有一种方法可以使用placement new将堆叠对象分配给分配的内存
- 在调用接收数组的方法时,模板化数组大小是不是一种糟糕的做法
- 有没有一种方法可以通过"typedef"为重新定义的基本类型定义特征和强制转换运算符
- 有没有一种"cleaner"的方法可以在指向基的指针向量中找到派生类的第一个实例?
- 有没有一种代码密度较低的方法来使用非默认构造函数初始化数组?
- 在 c++ 中,有一种方法可以创建一个包含地图作为值的树状地图?
- 有没有一种优雅而快速的方法来测试整数中的 1 位是否位于连续区域
- C++ STD 函数运算符:有没有一种方法可以通过函数将一个向量映射到另一个向量上?
- 找到一种有效的方法,在 2 个巨大的缓冲区上执行 MAX,每字节字节
- 寻找一种更好的方法来表示无符号字符数组
- 有没有一种通用的方法来实现不变量
- 有没有一种方法可以捕获进程中的堆栈溢出?C++Linux
- 使用类在C++中存储和列出变量/方法是否是一种好的做法
- 一种从内存中删除 UTF 字节的方法?