gpt4 book ai didi

c++ - 对静态常量结构的 undefined reference

转载 作者:行者123 更新时间:2023-11-28 07:07:10 29 4
gpt4 key购买 nike

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

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 的 undefined reference ...我可能忘记了什么?

谢谢! :)

最佳答案

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

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

您改为声明了静态非成员变量。

关于c++ - 对静态常量结构的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21629392/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com