Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
678 views
in Technique[技术] by (71.8m points)

qt - c++ struct does not name a type

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:

in header:

#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);
    //.....
};

in cpp file:

#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);
    //.....
}

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...