首页 \ 问答 \ 警告:'struct GLUquadric'的前向声明(warning: forward declaration of ‘struct GLUquadric’)

警告:'struct GLUquadric'的前向声明(warning: forward declaration of ‘struct GLUquadric’)

我得到以下内容

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


I get the following

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.

With this code

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; 

I understand why it does that, GLUquadricObj is in fact a foward declaration, BUT

I want to avoid this warning.

I would like either to suppress this warning for that sole function.

Or resolve the warning by including the right header. I used grep in /usr/include/GL and didn't find the complete type.

I'm using Arch Linux

mesa 7.8.2-3

and

gcc 4.5.1-1


原文:https://stackoverflow.com/questions/4129625
更新时间:2020-02-08 10:27

最满意答案

改变var cfilter = []; to var cfilter = $.cookie("listfilter");

这样您就可以加载更改的cookie并添加到它而不是覆盖它。

更好的代码实践是在使用之前检查cookie是否存在,但是你得到了我的提示。

您在实施我的更改时出错了:

 if ($.cookie("listfilter") !== 'null') {
                var cfilter = [];
            } else {
                var cfilter = $.cookie("listfilter");
            }

是错的,使用

 if ($.cookie("listfilter")) {
                var cfilter =  $.cookie("listfilter");
            } else {
                var cfilter =[];
            }

Change var cfilter = []; to var cfilter = $.cookie("listfilter");

This way you load the changed cookie and add to it instead of overwriting it.

Better code practice would be to check if the cookie exists before using it though, but you get my hint.

You made an error in implementing my change:

 if ($.cookie("listfilter") !== 'null') {
                var cfilter = [];
            } else {
                var cfilter = $.cookie("listfilter");
            }

is wrong, use

 if ($.cookie("listfilter")) {
                var cfilter =  $.cookie("listfilter");
            } else {
                var cfilter =[];
            }

相关问答

更多
  • 所以答案很简单,因为我在推送到数组的项目上有额外的括号: var newItem = [{ datetime: datetime, id: id, typeid: typeid, qty: 1}]; 需要 var newItem = {datetime: datetime, id: id, typeid: typeid, qty: 1}; So the answer was simply because i had extra brackets on the item i was pushing t ...
  • 只要阅读你的cookie,然后附加新的值