未定义的对静态const结构的引用

时间:2014-02-07 13:46:28

标签: c++ struct static const

我有这个标题(隐藏代码):

class DrawBuffers
{
public:
struct CubeCorners
{
    GLfloat corners[NUM_VERTS * ELEM_PER_NORM];
    CubeCorners(bool normalize);
};

static const CubeCorners POSITIONS;
static const GLfloat COLOR_DEFAULT[ELEM_PER_COLOR];
static const CubeCorners NORMALS;
static const GLuint INDICES[NUM_INDICES / NB_FACES][NB_INDICES_PER_FACE];
};

我在cpp中有这个:

const DrawBuffers::CubeCorners POSITIONS = DrawBuffers::CubeCorners(false);
const GLfloat DrawBuffers::COLOR_DEFAULT[] = {1.f, 1.f, 1.f, 1.f};
const DrawBuffers::CubeCorners NORMALS = DrawBuffers::CubeCorners(true);
const GLuint DrawBuffers::INDICES[][NB_INDICES_PER_FACE] = { //second indices
{0, 1, 2, // Back
2, 3, 0},

{7, 6, 5, // Front
5, 4, 7},

{4, 5, 1, // Left
1, 0, 4},

{3, 2, 6, // Right
6, 7, 3},

{4, 0, 3, // Bottom
3, 7, 4},

{6, 2, 1, // Top
1, 5, 6}};

我仍然在同一个.cpp文件中得到一个未定义的POSITIONS引用......我可能忘记了什么?

谢谢! :)

1 个答案:

答案 0 :(得分:1)

这些是静态成员,因此您需要在其定义中限定名称(正如您已经使用其中两个名称):

const DrawBuffers::CubeCorners DrawBuffers::POSITIONS = DrawBuffers::CubeCorners(false);
                               ^^^^^^^^^^^^^

您已经声明了静态非成员变量。

相关问题