由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问一个c++ 函数指针的问题
相关主题
C++ 一题问面试一题: OOP 设计 for "Evaluate Reverse Polish Notation"
请问为什么这个程序会出现RunTime Error指针函数, 函数指针, 头大。。
请教一个 c++ member function pointer 问题你们看过programming pearls (2nd edition English) or 正在看的同学们
one c++ question问道C的面试题
c++ 程序一问C的argc问题
请教一个入门级的C的指针问题为什么我这段简单的程序segment fault
array of pointers to functionsbloomberg assessment的机经,c语言的(20道题)
Interview questions, BloombergC++ online Test 又一题
相关话题的讨论汇总
话题: int话题: calculator话题: calpointer话题: add话题: fun
进入JobHunting版参与讨论
1 (共1页)
b******b
发帖数: 300
1
class Calculator{
public:
int add(int a, int b){
return a+b;
}
int subtraction(int a , int b){
return a-b;
}

};
typedef int(Calculator::*CalPointer)(int,int);
int _tmain(int argc, _TCHAR* argv[])
{
CalPointer fun;
fun = Calculator::add;
fun(2,4);
}
总是报错,求问 应该怎么写函数指针啊
h**6
发帖数: 4160
2
这不是静态函数,不同通过双冒号访问。
要么在Calculator类内部调用,
要么把add改成静态函数,
要么定义一个Calculator Object。
b******b
发帖数: 300
3
请问如果定义一个object应该怎么写呢

【在 h**6 的大作中提到】
: 这不是静态函数,不同通过双冒号访问。
: 要么在Calculator类内部调用,
: 要么把add改成静态函数,
: 要么定义一个Calculator Object。

j*****y
发帖数: 1071
4
加一个地址符号
fun = &Calculator::add;

class Calculator{
public:
int add(int a, int b){
return a+b;
}
int subtraction(int a , int b){
return a-b;
}

};
typedef int(Calculator::*CalPointer)(int,int);
int _tmain(int argc, _TCHAR* argv[])
{
CalPointer fun;
fun = Calculator::add;
}
总是报错,求问 应该怎么写函数指针啊.................

【在 b******b 的大作中提到】
: class Calculator{
: public:
: int add(int a, int b){
: return a+b;
: }
: int subtraction(int a , int b){
: return a-b;
: }
:
: };

h**6
发帖数: 4160
5
class Calculator{
public:
int add(int a, int b){
return a+b;
}
int subtraction(int a , int b){
return a-b;
}
};
typedef int(Calculator::*CalPointer)(int,int);
Calculator calc;
CalPointer func1 = &Calculator::add;
int a = (calc.*func1)(2, 3);
std::function func2 = std::bind(&Calculator::add, &calc, _1, _
2);
int b = func2(4, 5);
printf("a=%d, b=%d\n", a, b);
1 (共1页)
进入JobHunting版参与讨论
相关主题
C++ online Test 又一题c++ 程序一问
这题哪错了?请教一个入门级的C的指针问题
在子函数内开内存,返回主函数指针然后释放空间是不是很糟糕的(转载)array of pointers to functions
这个看着很白痴的问题有更好的解法吗?Interview questions, Bloomberg
C++ 一题问面试一题: OOP 设计 for "Evaluate Reverse Polish Notation"
请问为什么这个程序会出现RunTime Error指针函数, 函数指针, 头大。。
请教一个 c++ member function pointer 问题你们看过programming pearls (2nd edition English) or 正在看的同学们
one c++ question问道C的面试题
相关话题的讨论汇总
话题: int话题: calculator话题: calpointer话题: add话题: fun