【发布时间】:2017-12-02 08:08:59
【问题描述】:
我不断收到non-standard syntax; use '&' to create a pointer to member
我不知道为什么它不起作用。
如果 Resize 函数是全局的,它就可以工作
小例子:
#include <GLFW/glfw3.h>
class test {
public:
test(){}
~test(){}
void resize(GLFWwindow* window, int new_width, int new_height) {}
}resizer;
int main(){
auto newwindow = glfwCreateWindow(1, 1, "test", NULL, NULL);
glfwSetWindowSizeCallback(newwindow, resizer.resize);
return 0;
}
最初的问题使用 static 作为函数得到了解决,但这在我想要做的事情中产生了不同的错误是问题的简化问题:
//rough replication of lib functions cannot change these
typedef void(* windowsizefun)(int,int);
void setWindowSizeCallback(windowsizefun fun){}
//the problem
class windowhandler{
private:
int width, height;
static void resize(int new_width, int new_height) {
width =new_width; height =new_height; //error
}
public:
test(){
width =100; height =100;
setWindowSizeCallback(windowhandler::resize);
}
}
int main(){
windowhandler newWindow();
return 0;
}
【问题讨论】:
-
在本页顶部的搜索框中输入错误信息。
-
我找不到任何与 gflw 回调相关的内容
-
s/
window.Resize/&window::Resize并确保将Resize()声明为static。 -
@jeana glfw 与它几乎没有关系。这是一个更普遍的问题。
-
@user0042
a storage class may not be specified here我将 resize 设为静态,window.setResize(&window::Resize);给出:: must be a class or namespace name