Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.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
C++ 初始化类时如何用非静态类函数初始化静态函数指针?_C++_Class_Function Pointers - Fatal编程技术网

C++ 初始化类时如何用非静态类函数初始化静态函数指针?

C++ 初始化类时如何用非静态类函数初始化静态函数指针?,c++,class,function-pointers,C++,Class,Function Pointers,定义(核心h): 也在Core.cpp中重新定义。此代码导致错误: foolink = this->step; 错误: Engine/Core.cpp:31: error: argument of type 'int (Core::)(int*, char*, key*, key*)' does not match 'int (*)(int*, char*, key*, key*)' 指针使用: (*foolink)(NULL, NULL, NULL, NULL); 怎么了?请帮帮我

定义(核心h):

也在Core.cpp中重新定义。此代码导致错误:

foolink = this->step;
错误:

Engine/Core.cpp:31: error: argument of type 'int (Core::)(int*, char*, key*, key*)' does not match 'int (*)(int*, char*, key*, key*)'
指针使用:

(*foolink)(NULL, NULL, NULL, NULL);

怎么了?请帮帮我

此->步骤的类型必须是返回整数并将int*、char*、key*和key*作为参数的函数。显然不是。记住,将类方法分配给普通函数是不可行的;它们都必须是方法,或者都是普通函数,但不是混合函数,我怀疑您正在尝试这样做。

此->步骤的类型必须是返回整数并将int*、char*、key*和key*作为参数的函数。显然不是。记住,将类方法分配给普通函数是不可行的;它们都必须是方法,或者是正常函数,而不是混合函数,这就是我猜想的,在C++程序中,大多数<强>函数是<强>成员函数< /强>;也就是说,它们是类的一部分。不允许使用普通的函数指针指向成员函数;相反,您必须使用成员函数指针

在您的情况下,您可以将其定义为

     v you have to name the class here
int (YourClass::*foolink)(int*, char*, key*, key*);
foolink = &YourClass::step;

// This is how you can call the function via member function pointer
YourClass object, *pObject = &object;
// One way is to envoke the function from object
(object.*foolink)(...);
// The other way is from pointer to object
(pObject->*foolink)(...);
C++常见问题解答


在C++程序中,大多数<强>函数是<强>成员函数< /强>;也就是说,它们是类的一部分。不允许使用普通的函数指针指向成员函数;相反,您必须使用成员函数指针

在您的情况下,您可以将其定义为

     v you have to name the class here
int (YourClass::*foolink)(int*, char*, key*, key*);
foolink = &YourClass::step;

// This is how you can call the function via member function pointer
YourClass object, *pObject = &object;
// One way is to envoke the function from object
(object.*foolink)(...);
// The other way is from pointer to object
(pObject->*foolink)(...);
C++常见问题解答


我怎么称呼它?(核心::*傻瓜链接)(空,空,空,空)不工作@HiTECNOLOGYs:我将更新我的答案,以包含函数的调用:)我如何调用它?(核心::*傻瓜链接)(空,空,空,空)不工作@HiTECNOLOGYs:我将更新我的答案,以包含函数的调用:)