Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
671 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...