多态性:“指向绑定函数的指针只能用于调用该函数". [英] Polymorphism: "A pointer to a bound function may only be used to call the function"
本文介绍了多态性:“指向绑定函数的指针只能用于调用该函数".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将代码分成多个文件,但这是我不明白的一件事.
I'm separating my code into multiple files, but this is one thing I don't get.
在graphics.h中:
In graphics.h:
...
class graphics {
public:
virtual void SizeMod(int w, int h);
...
}
在graphics.cpp中:
In graphics.cpp:
...
void SizeMod(int w, int h) {
//Code here.
}
...
在main.cpp中:
In main.cpp:
...
graphics g;
...
int main (int argc, char **argv) {
...
glutReshapeFunc(g.SizeMod);
...
}
错误:
error C3867: 'graphics::SizeMod': function call missing argument list; use &graphics::SizeMod to create a pointer to member
所以我做到了:
...
graphics g;
...
int main (int argc, char **argv) {
...
glutReshapeFunc(&graphics::SizeMod);
...
}
它仍然给我一个错误(一个不同的错误). 有什么办法解决这个问题吗?
It still gives me an error (a different one). Anything to solve this problem?
推荐答案
它不会以这种方式工作,因为SizeMod
是非静态的类成员方法,因此需要调用this
.您必须将SizeMod
设为静态.
it won't work this way because SizeMod
is a non-static class member method, so it needs this
to be called on. You have to make SizeMod
static.
这篇关于多态性:“指向绑定函数的指针只能用于调用该函数".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文