【问题标题】:warning: forward declaration of ‘struct GLUquadric’警告:“struct GLUquadric”的前向声明
【发布时间】:2010-11-09 01:13:04
【问题描述】:

我得到以下内容

x.cpp: In member function ‘X’:
x.cpp:153:10: warning: possible problem detected in invocation of delete operator:
x.cpp:146:19: warning: ‘quadric’ has incomplete type /usr/include/GL/glu.h:271:7: warning: forward declaration of ‘struct GLUquadric’
x.cpp:153:10: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined.

使用此代码

146: GLUquadricObj * quadric;
147: quadric = gluNewQuadric();
148: gluQuadricNormals(quadric, GLU_SMOOTH);
149: gluQuadricTexture(quadric, GL_TRUE);
150:
151: gluSphere(quadric, object.radius(), slices, stacks);
152:
153: delete quadric; 

我明白为什么会这样,GLUquadricObj 实际上是一个前向声明,但是

我想避免这个警告。

我想取消该唯一功能的警告。

或者通过包含正确的标题来解决警告。我在 /usr/include/GL 中使用了 grep 并没有找到完整的类型。

我正在使用 Arch Linux

台面 7.8.2-3

gcc 4.5.1-1

【问题讨论】:

    标签: linux opengl gcc-warning


    【解决方案1】:

    GLUquadricObj 需要使用以下命令删除:

    gluDeleteQuadric(GLUquadricObj *);
    

    【讨论】:

      【解决方案2】:

      您不能将delete 用于未使用new 分配的对象。在不了解 OpenGL 的情况下,我很确定您必须在这里使用 gluDeleteQuadric

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-26
        • 1970-01-01
        • 1970-01-01
        • 2011-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-14
        相关资源
        最近更新 更多