由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 关于Function Pointer的简单问题,望指教
相关主题
谁给解释一下这个c questionQuestion: Given a pointer to a function
出个题考考大家:)a c++ question
question: retrieving function pointers to VC API entry pointspointer to function
about STL functor and function pointers把一个function pointer作为参数传入一个function的语法是什么?
function pointer 和 call-back function 有什么区别?can you insert several function pointers into a queue ?
Questions about c codec++ question
pointer to override function?听说pointer to member function只支持最多128个virtual functi
c++太神奇了C++ Function Pointer Array 的问题
相关话题的讨论汇总
话题: int话题: functocall话题: function话题: pointer话题: return
进入Programming版参与讨论
1 (共1页)
s*******o
发帖数: 392
1
刚开始看www.cplusplus.com上的tutorial文档,在73页写到了关于function pointer
的用
法,可是我录入后报错,希望大家帮忙看看
#include
using namespace std;
int addition (int a, int b)
{
return(a + b);
}
int subtraction (int a, int b)
{
return(a - b);
}
int operation(int x, int y, int (* functocall(int x, int y)))
{
int g;
g = (*functocall(x, y));
return(g);
}
int main()
{
int m;
int (*minus)(int, int) = subtraction;
m = operation(7 , 5, minus);

std::cout << m;
system("PAUSE");
return 0;
}
他报的错误时
d:\backup\dropboxsas\dropbox\coding\vs2010\helloworld\addfunction\
addfunction.cpp(
27): error C2664: 'operation' : cannot convert parameter 3 from 'int (__
cdecl *)
(int,int)' to 'int *(__cdecl *)(int,int)'
1> This conversion requires a reinterpret_cast, a C-style cast or
function-style cast
可是我写的和他的例子一摸一样啊,大虾帮下,先谢谢了
X****r
发帖数: 3557
2
是(*functocall)(int x, int y),不是(* functocall(int x, int y))
注意括号位置。

pointer

【在 s*******o 的大作中提到】
: 刚开始看www.cplusplus.com上的tutorial文档,在73页写到了关于function pointer
: 的用
: 法,可是我录入后报错,希望大家帮忙看看
: #include
: using namespace std;
: int addition (int a, int b)
: {
: return(a + b);
: }
: int subtraction (int a, int b)

z****e
发帖数: 2024
3
还有
g = (*functocall(x, y));

g=(*functocall) (x, y);

【在 X****r 的大作中提到】
: 是(*functocall)(int x, int y),不是(* functocall(int x, int y))
: 注意括号位置。
:
: pointer

1 (共1页)
进入Programming版参与讨论
相关主题
C++ Function Pointer Array 的问题function pointer 和 call-back function 有什么区别?
function in c++Questions about c code
C++ Q90 - Q92 (转载)pointer to override function?
菜鸟问个C++问题c++太神奇了
谁给解释一下这个c questionQuestion: Given a pointer to a function
出个题考考大家:)a c++ question
question: retrieving function pointers to VC API entry pointspointer to function
about STL functor and function pointers把一个function pointer作为参数传入一个function的语法是什么?
相关话题的讨论汇总
话题: int话题: functocall话题: function话题: pointer话题: return