简体   繁体   English

C ++枚举EXC_BAD_ACCESS

[英]C++ enum EXC_BAD_ACCESS

I have a problem with the enumerations in c++ 我在C ++中的枚举有问题
I don't understand why if I define two variables with the same enumeration it give EXC_BAD_ACCESS do you have an idea why? 我不明白为什么我用相同的枚举定义两个变量会给EXC_BAD_ACCESS,你知道为什么吗? if I define only one varible it is fine 如果我只定义一个变量,那很好
here is the code... 这是代码...

enum directions{
    UP,
    DOWN,
    RIGHT,
    LEFT,
    IN,
    OUT,
    FW,
    RW
};

class Snake
{
private:
    enum directions head_dir;
    enum directions head_dir_ask; //if I comment this... the program work fine..
    (... other stuff...)
};

thanks for the help in advance 我在这里先向您的帮助表示感谢
the code is about 10 files... it will be like too long to post, 该代码大约有10个文件...发布时间太长,
anyway... 无论如何...
I'm using OpenGL and Qt 我正在使用OpenGL和Qt

MainProject::MainProject(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainProject)
{
    ui->setupUi(this);
    startTimer(1000);
    glwidget = new MyGLBox(ui->centralWidget);
    ui->GLlayout->addWidget(glwidget); // <line where the complier retruns the EXC_BAD_ACCESS
}

MyGLBox constructor: MyGLBox构造函数:

MyGLBox::MyGLBox(QWidget *parent):QGLWidget(parent){
   XRot = YRot = ZRot = 0;
    theta1 = theta2 = phi = 0;
}

There's not nearly enough information in your question to point you in any particular direction. 您的问题中没有足够的信息来指出您的任何特定方向。 However, it's almost certainly because somewhere else in your code there is some pointer manipulation that goes wild and ends up accessing something undefined. 但是,几乎可以肯定,因为在代码的其他位置 ,有些指针操作变得疯狂,最终导致访问未定义的内容。 Changing the memory layout of objects (such as adding or removing an unused member) can temporarily mask such an error -- which is not a good thing because instead if preventing the error it is just transforming it from a highly visible and debuggable crash to something subtler and harder to detect, but still an error, whose eventual effects can be much more baffling. 更改对象的内存布局(例如添加或删除未使用的成员)可以暂时掩盖此类错误-这不是一件好事,因为如果防止该错误,它只是将其从高度可见且可调试的崩溃转换为某种错误更微妙,更难检测,但仍然是一个错误,其最终影响可能会更加令人困惑。

You should run your code in a debugger and inspect what it is doing when you get the exception. 您应该在调试器中运行代码,并在获取异常时检查其功能。 (And for your own sake, don't change the program in any way that makes the crash go away until you have understood why it crashed and are sure you have fixed the underlying cause). (出于您自己的考虑, 请不要以任何使崩溃消失的方式更改程序,直到您了解崩溃的原因并确保已解决根本原因为止)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM