c ++ struct 未命名类型

c++ struct does not name a type(c ++ struct 未命名类型)
本文介绍了c ++ struct 未命名类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在头文件中定义一个结构,然后在相应的 .cpp 文件中设置其成员.为此,我使用了一个函数,该函数应该在其范围内创建一个(相同的)结构,然后返回它.像这样:

I am defining a structure in a header file, and then setting its members in the corrosponding .cpp file. For doing this I am using a function that is supposed to create a (same) structure in its scope, and then return it. Something like this:

在标题中:

#include <things>
class GLWindow : public QGLWidget, public QGLFunctions
{
    Q_OBJECT
public:
    GLWindow(QWidget *parent = 0);
    ~GLWindow();

    //....
    struct Drawable
    {
        GLuint     vertexBuffer;
        GLuint     indexBuffer;
        int        faceCount;
        QMatrix4x4 transform;
    }cube;
    GLuint cubeTex;

    Drawable CreateDrawable(GLfloat* C_vertices, GLfloat* C_tex, GLfloat* C_normals, GLushort* C_facedata, int faces);
    //.....
};

在 cpp 文件中:

#include "glwindow.h"

Drawable GLWindow :: CreateDrawable(GLfloat *C_vertices, GLfloat *C_tex, GLfloat *C_normals, GLushort *C_facedata, int faces)
{
    int faceCount =faces;

    QMatrix4x4 Transform;
    Transform.setToIdentity();

    GLuint VB;
    /*Create vertexbuffer...*/

    GLuint IB;
    /*Create indexbuffer...*/

    Drawable drawable;
    drawable.faceCount = fCount;
    drawable.transform = Transform;
    drawable.vertexBuffer = VB;
    drawable.indexBuffer = IB;

    return drawable;
}

void GLWindow :: someOtherFunction()
{
    //.....
    cube = CreateDrawable(cube_vertices, cube_tex, cube_normals, cube_facedata, cube_face);
    //.....
}

我收到一个错误,指出 'Drawable' 没有命名类型,但我不明白为什么我会收到这个错误,或者我可以做些什么来消除它.>

I am getting an error stating that 'Drawable' does not name a type, but I can't comprehend why I am getting this error, or what I can do to eliminate it.

推荐答案

你需要在cpp文件中限定Drawable:

You need to qualify Drawable in the cpp file:

GLWindow::Drawable GLWindow :: CreateDrawable(GLfloat *C_vertices, GLfloat *C_tex, GLfloat *C_normals, GLushort *C_facedata, int faces)

在 cpp 文件中,在成员方法之外,您在类上下文之外进行操作.在方法内部你可以使用Drawable,但在外部(包括返回类型),你需要使用GLWindow::Drawable.

In the cpp file, outside the member methods, you're operating outside the class context. Inside the methods you can use Drawable, but outside (including return type), you need to use GLWindow::Drawable.

如果你实际上从方法中返回了一个 Drawable,而不是一个 void - 也是一个错误.

That's if you're actually returning a Drawable from the method, not a void - also an error.

这篇关于c ++ struct 未命名类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Bring window to front -gt; raise(),show(),activateWindow() don’t work(把窗户放在前面 -raise(),show(),activateWindow() 不起作用)
How to get a list video capture devices NAMES (web cameras) using Qt (crossplatform)? (C++)(如何使用 Qt(跨平台)获取列表视频捕获设备名称(网络摄像机)?(C++))
How to compile Qt as static(如何将 Qt 编译为静态)
C++ over Qt : Controlling transparency of Labels and Buttons(C++ over Qt:控制标签和按钮的透明度)
How to know when a new USB storage device is connected in Qt?(Qt如何知道新的USB存储设备何时连接?)
What is an event loop in Qt?(Qt 中的事件循环是什么?)