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.
You need to qualify
Drawablein the cpp file: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 useGLWindow::Drawable.That’s if you’re actually returning a
Drawablefrom the method, not avoid– also an error.