我在头文件中定义一个结构,然后在corrosponding .cpp文件中设置它的成员.为此,我使用的函数应该在其范围内创建(相同)结构,然后返回它.像这样的东西:
在标题中:
#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);
//.....
};
Run Code Online (Sandbox Code Playgroud)
在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 …Run Code Online (Sandbox Code Playgroud) 我想知道为什么给全局变量赋值会导致错误
#include <iostream>
using namespace std;
int x = 5;
x = 3; // error: C++ requires a type specifier for all declarations
Run Code Online (Sandbox Code Playgroud)
我不是刚刚在上面的行中声明了吗?好吧,让我们看看 x 是否存在;
#include <iostream>
using namespace std;
int x = 5;
x = 3; // error: C++ requires a type specifier for all declarations
Run Code Online (Sandbox Code Playgroud)
好的,所以它确实同意 x 已定义,但类型“还不是”int。有人可以解释这种行为吗,你怎么称呼这种行为?它是怎么发生的?为什么这样设计?