成员函数指针使用
2016-04-22 10:49
281 查看
通用一般函数指针 。。。
typedef void (*Func)(...);
通用函数指针(不限参数个数)
通用获取成员函数返回值值函数(不限类型)
class Test
{
public:
void display(int a)
{
cout << a << endl;
}
int test(int a, int b)
{
cout << a + b << endl;
return a + b;
}
int tt()
{
return 100;
}
char* cc()
{
return "hello world.";
}
private:
};
typedef void ( Test::*common)(...);
template<typename T,typename V>
void getValue( common com, V v, T &t)
{
t = (v.*(T (V::*)(...))com)();
}
int main(void)
{
One *one = new Two;
Test test;
common cmp = (common)&Test::test;
(test.*cmp)(5,5);
cmp = (common)&Test::display;
cmp = (common)&Test::tt;
int d;
getValue(cmp, test,d);
cout << d << endl;
return 0;
}
typedef void (*Func)(...);
通用函数指针(不限参数个数)
通用获取成员函数返回值值函数(不限类型)
class Test
{
public:
void display(int a)
{
cout << a << endl;
}
int test(int a, int b)
{
cout << a + b << endl;
return a + b;
}
int tt()
{
return 100;
}
char* cc()
{
return "hello world.";
}
private:
};
typedef void ( Test::*common)(...);
template<typename T,typename V>
void getValue( common com, V v, T &t)
{
t = (v.*(T (V::*)(...))com)();
}
int main(void)
{
One *one = new Two;
Test test;
common cmp = (common)&Test::test;
(test.*cmp)(5,5);
cmp = (common)&Test::display;
cmp = (common)&Test::tt;
int d;
getValue(cmp, test,d);
cout << d << endl;
return 0;
}
相关文章推荐
- 知道这20个正则表达式,能让你少写1,000行代码
- 求输入的几个数的和
- Mysql函数汇总
- Linux下安装Android Studio
- leetcode——238——Product of Array Except Self
- CableModem原理
- 安装ubuntu已将该虚拟机配置 为使用64位客户机操作系统错误
- [027]八大排序算法详解——归并排序
- Class create, device create, device create file
- CocoaPods中Podfile详解
- mac 安装 Android Studio
- 【转】DBMS_PARALLEL_EXECUTE
- vs+opencv中findcontours崩溃的问题
- Git学习(2)Git 安装
- Android Paint详解
- C++作业4
- Android程序开发之UIScrollerView里有两个tableView
- 一个很city的问题
- c++第三次作业
- cocos中使用tinyxml2遇到的一个小问题