0
所以我想找到一个替代我在这里做什么,因为它在结构中使用零大小的数组是非法的。什么代码可以完成几乎相同的任务?替代零大小结构
你可以看到我基本上试图做的是创建一个具有四条边的动画对象的结构。
struct Sprite
{
double x;
double y;
int textureFront[];
int textureBack[];
int textureRight[];
int textureLeft[];
};
int boxAnimation[7] = {10,5,6,2,76,8,4};
Sprite sprite[8] =
{
{20.5, 11.5, {10}},
{18.5, 4.5, boxAnimation},
{10.0, 4.5, {10}},
{10.0, 12.5, {10}},
{3.5, 6.5, {10}},
{3.5, 20.5, {10}},
{3.5, 14.5, {10}},
{14.5, 20.5, {10}},
};
只有textureFront被分配在这些例子中。
那么你想要的是一个指针? – kfsone
如果您有特定的大小,只需使用'std :: array',否则使用'std :: vector'。 – chris
@kfsone,我不了解你,但如果我是这个班的使用者,我将不必为每一个人手动管理内存。 – chris