我有这个标题(带有隐藏代码):
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);
^^^^^^^^^^^^^
相反,您声明了静态非成员变量。