[英]Function Pointer Issues C++ / Arduino
i have a header file with a class and several declaration and non-static member functions like this: 我有一个带有一个类的头文件,以及几个这样的声明和非静态成员函数:
//foo.h
...
#include <bar.h>
class foo
{
...
public:
void myFunction();
};
and a header file with a struct and a class like: 以及具有结构和类的头文件:
//bar.h
...
struct baz
{
class foo;
...
void (foo::*functionPointer)() = NULL;
}
class bar
{
...
public:
static myOtherFunction();
};
and i want to address the function pointer in bar.cpp's static function "myOtherFunction" like: 我想解决bar.cpp的静态函数“ myOtherFunction”中的函数指针,例如:
void bar::myOtherFunction()
{
...
baz b = baz();
b.functionPointer = &foo::myFunction;
}
but this gets me an compiler error: 但这会给我一个编译器错误:
bar.cpp:247:22: error: cannot convert 'void (foo::*)()' to 'void baz::foo::*)()' in assignment
b.functionPointer = &foo*:myFunction;
Error compiling
Pretty Sure that this is an obvious fault for anyone experienced in c/c++ but for now i'm stuck and would be really grateful about some help. 可以肯定的是,对于任何有c / c ++经验的人来说,这都是明显的错误,但是现在我被困住了,非常感谢您的帮助。 Thank you... 谢谢...
If you have access to C++11 libraries/classes in your compiler, include the functional
library. 如果可以在编译器中访问C ++ 11库/类,请包括functional
库。 Description here . 在这里说明。 It will show a way to make fully "packed" objects that have a reference to both the method you want, and the class instance. 它将显示一种制作完全“打包”对象的方法,这些对象同时引用所需的方法和类实例。
If not, read the Pointers to Members section of the C++ FAQ very VERY closely. 如果没有,请非常仔细地阅读C ++ FAQ的“ 指向成员的指针”部分。 That's supported by everything everywhere as a core part of the language. 作为语言的核心部分,所有地方都支持这一点。
Good luck. 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.