2012-03-07 125 views
4

我正在頭文件中定義一個結構,然後在corrosponding .cpp文件中設置它的成員。爲此,我正在使用一個應該在其範圍內創建(相同)結構的函數,然後將其返回。事情是這樣的:C++ struct不會命名一個類型

在頭

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

我得到一個錯誤,指出'繪製對象' 沒有指定類型,但我無法理解爲什麼我得到這個錯誤,或者我能做些什麼來消除它。

+1

可能是錯字'CreateDrawable'返回'void'在頭聲明&'Drawable'源 – 2012-03-07 07:53:10

+0

在你的頭文件,應該不會是'可繪製CreateDrawable(...)'取代'無效CreateDrawable(。 ..)'? – Treb 2012-03-07 07:55:00

+0

another.anon.coward和Treb是的。編輯它。 – 2012-03-07 07:56:47

回答

8

您需要在cpp文件出線Drawable

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

在cpp文件中,成員方法外,你的班級環境之外運行。在內部方法中,您可以使用Drawable,但在外部(包括返回類型),您需要使用GLWindow::Drawable

這就是如果你實際上從方法返回Drawable而不是void - 也是一個錯誤。