繁体   English   中英

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

[英]Undefined reference to a static const struct

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

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引用...我可能忘记了什么?

谢谢! :)

这些是静态成员,因此您需要在其定义中限定名称(就像您已经对其中两个所做的那样):

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

相反,您声明了静态非成员变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM