0
我有一個簡單的C++應用程序。當我嘗試使用sizeof
和一個成員變量時,我得到一個錯誤"Incomplete type is not allowed"
。當我使全局變量(如在main
之外定義它)我沒有得到這個錯誤。在C++中使用受保護的成員數組時不完整的類型
這是爲什麼?
在代碼中我的問題是這樣的:
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);
}
}
除了別的,受保護的數據是一個壞主意。 –
如果您在類之外而不是內聯中定義「example :: init」,會發生什麼情況? – bjhend