Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用typedef指针指向类中的函数 我列举了C++类中函数指针的不同用法。它可能看起来没用,但我想在类中调用combiner成员函数(useAdd) #包括 类myclass; 使用名称空间std; typedef int(myclass::*myFuncType)(int,int); 类myclass { 私人: INTA; int b; 公众: ~myclass(){}; 整数相加(常数整数x1,常数整数x2) { 返回(x1+x2); } 整数倍(常数整数x1,常数整数x2) { 返回(x1*x2); } 整型组合器(常数整型x1、常数整型x2、myFuncType func) { 返回(本->*函数)(x1,x2); } void useAdd(常数int x1,常数int x2) { cout_C++_Function Pointers - Fatal编程技术网

使用typedef指针指向类中的函数 我列举了C++类中函数指针的不同用法。它可能看起来没用,但我想在类中调用combiner成员函数(useAdd) #包括 类myclass; 使用名称空间std; typedef int(myclass::*myFuncType)(int,int); 类myclass { 私人: INTA; int b; 公众: ~myclass(){}; 整数相加(常数整数x1,常数整数x2) { 返回(x1+x2); } 整数倍(常数整数x1,常数整数x2) { 返回(x1*x2); } 整型组合器(常数整型x1、常数整型x2、myFuncType func) { 返回(本->*函数)(x1,x2); } void useAdd(常数int x1,常数int x2) { cout

使用typedef指针指向类中的函数 我列举了C++类中函数指针的不同用法。它可能看起来没用,但我想在类中调用combiner成员函数(useAdd) #包括 类myclass; 使用名称空间std; typedef int(myclass::*myFuncType)(int,int); 类myclass { 私人: INTA; int b; 公众: ~myclass(){}; 整数相加(常数整数x1,常数整数x2) { 返回(x1+x2); } 整数倍(常数整数x1,常数整数x2) { 返回(x1*x2); } 整型组合器(常数整型x1、常数整型x2、myFuncType func) { 返回(本->*函数)(x1,x2); } void useAdd(常数int x1,常数int x2) { cout,c++,function-pointers,C++,Function Pointers,获取指向成员的指针在定义成员的类内外都有相同的语法;您需要 cout << "using inside the class " << combiner(x1, x2, &myclass::add) << endl; 我可以假设您想询问如何将指针作为参数传递给成员函数吗?很简单:您可以像传递任何其他值一样传递指向成员函数的指针,借助操作符&的地址。如果这不是您的问题,那么您的问题是什么?请刷新,以及。 cout << "using insi

获取指向成员的指针在定义成员的类内外都有相同的语法;您需要

cout << "using inside the class " << combiner(x1, x2, &myclass::add) << endl;

我可以假设您想询问如何将指针作为参数传递给成员函数吗?很简单:您可以像传递任何其他值一样传递指向成员函数的指针,借助操作符
&
的地址。如果这不是您的问题,那么您的问题是什么?请刷新,以及。
cout << "using inside the class " << combiner(x1, x2, &myclass::add) << endl;