gpt4 book ai didi

c++ - 在 C++ 中使用 protected 成员数组时类型不完整

转载 作者:行者123 更新时间:2023-11-28 01:44:59 28 4
gpt4 key购买 nike

我有一个简单的 C++ 应用程序。当我尝试将 sizeof 与成员变量一起使用时,出现错误,提示 "Incomplete type is not allowed"。当我将变量设置为全局变量(比如在 main 之外定义它)时,我没有收到此错误。

这是为什么?

在代码中我的问题是这样的:

class example : public application
{
private:
void init()
{
// The "sizeof" call raises an error, "incomplete type is not allowed"
glNamedBufferStorage(vbo, sizeof(vertices), vertices, 0);
}

const GLfloat vertices[] = {1, 2, 3};
}

如果我在类之外定义 const GLfloat vertices[] = {1, 2, 3};(使其成为全局的),这将起作用。

const GLfloat vertices[] = {1, 2, 3};
class example : public application
{
private:
void init()
{
// This works
glNamedBufferStorage(vbo, sizeof(vertices), vertices, 0);
}
}

最佳答案

声明时需要指定顶点的大小。您不能使用初始化器来指定类中空数组的大小(语言规范部分 dcl.init.aggr,第 5 段)。

const GLfloat vertices[3] = {1, 2, 3};

关于c++ - 在 C++ 中使用 protected 成员数组时类型不完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45527434/

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