【发布时间】:2015-08-31 15:00:21
【问题描述】:
我正在尝试为我的 openGL 项目创建一个 textureLoader 类,但我无法在我的类构造函数中初始化一个纹理数组,因为该数组不会接受任何内容,除非它是一个 const int。
给你画一幅简单的图画……
myFunction(NUM)
{
GLuint textures[NUM];
}
我过去的失败
myConstructor(const int& num)
{
GLuint textures[num] //error: expression must have a constant value
}
myConstructor(int num)
{
std::vector <GLuint> textures(num);//works but wait
glGenTextures(num, textures) // <--- doesn't work cause vectors.
}
myConstructor(int num)
{
const int PLEASE_WORK = num;
GLuint textures[PLEASE_WORK]; // doesn't work.
【问题讨论】:
-
您尝试的方法(
vector方法除外)称为可变长度数组,C99 支持,但 C++ IIRC 不支持。 -
我会查一下,谢谢。我在想至少第三种选择应该有效。
-
不是因为在编译过程中数组的大小是未知的。