使用过剩显示时遇到问题
我尝试在 C++ 中使用 Glut,但是当我尝试将显示函数放入 Renderer 类中时遇到问题。
我的错误是: 错误 C2227:'->display' 的左侧必须指向类/结构/联合/通用类型
到目前为止,我有以下内容:
class Renderer
{
public:
Renderer *gRenderer;
...
}
int Renderer::start(Renderer r)
{
...
setRenderer(r);
glutDisplayFunc(&Renderer::staticDisplay);
...
}
void Renderer::setRenderer(Renderer r){
*gRenderer = r;
}
void Renderer::staticDisplay(){
gRenderer->display();
}
void Renderer::display()
{
... show stuff
}
我不确定我做错了什么:(
感谢所有帮助!
I am trying to use Glut in C++, but I am having issues when I try to put my display function within the Renderer class.
The error i have is:
error C2227: left of '->display' must point to class/struct/union/generic type
So far I have the following :
class Renderer
{
public:
Renderer *gRenderer;
...
}
int Renderer::start(Renderer r)
{
...
setRenderer(r);
glutDisplayFunc(&Renderer::staticDisplay);
...
}
void Renderer::setRenderer(Renderer r){
*gRenderer = r;
}
void Renderer::staticDisplay(){
gRenderer->display();
}
void Renderer::display()
{
... show stuff
}
I am not sure what I am doing wrong :(
Thanks for all the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
staticDisplay
是静态函数(顾名思义),则无法从中访问gRenderer
(它是一个成员变量)。您需要类的实例才能执行此操作,而静态方法则没有。If
staticDisplay
is a static function (as the name suggests), you can't accessgRenderer
, which is a member variable, from it. You need an instance of the class to do that, while static methods have none.