错误声明是不兼容的c ++(数组)

时间:2014-02-20 07:04:32

标签: c++ arrays declaration

您好我被要求将包含3d多维数据集信息的数组设置为“null”,以便它们可以用于接收从txt文件中绘制它们所需的数据,但是已经运行了此错误。

任何帮助都将不胜感激。

多维数据集头文件

class Cube
{

private:

    static int numVertices, numColours, numIndices;
    static Vertex indexedVertices[];
    static Color indexedColors[];
    static GLushort indices[];
    GLfloat _rotation;
    GLfloat _CubeX;
    GLfloat _CubeY;
    GLfloat _CubeZ;

多维数据集cpp文件

    Vertex *Cube::indexedVertices = nullptr;
Color *Cube::indexedColors[] = nullptr;
GLushort  *Cube::indices[] = nullptr;

错误出现在indexedVertices,indexedColors和indices

1 个答案:

答案 0 :(得分:2)

数组不能为空。

另外,您没有在其定义中指定数组的大小。

此外,您的定义与您的声明不符!比较:

static Vertex indexedVertices[]; // declares an array of Vertexes
Vertex *Cube::indexedVertices = nullptr; // defines a pointer to a Vertex

同样比较:

static Color indexedColors[]; // declares an array of Colors
Color *Cube::indexedColors[] = nullptr; // defines an array of pointers to Colors

数组不是指针。有时语言会“帮助”将数组转换为指针(例如,indexedVertices在表达式中使用时转换为&indexedVertices[0],但它们不是同一个东西!