简体   繁体   English

数组赋值中的初始值设定项过多

[英]Too many initializer values in array assignment

I'm doing Sierpinski carpet using recursion.我正在使用递归做谢尔宾斯基地毯。 In function DrawCarpet in linen, where I redefine a value I got error "To many initializer values".在亚麻布中的 DrawCarpet 函数中,我重新定义了一个值,但出现错误“To many initializer values”。 Do somebody know what I'm doing wrong?有人知道我做错了什么吗?

typedef float point[2];

float x = 100;
float y = 100;
point a = {  x , y  };
int grade = 4;

void DrawCarpet(point a, GLfloat width, GLfloat grade)
{


    if(grade>0)
    {


        width = width / 3;

        DrawCarpet(a, width, grade - 1);
        a = {  x - width , y };
        DrawCarpet(a, width, grade - 1);
        a = {  x - 2*width , y  };
        DrawCarpet(a, width, grade - 1);
        a = {  x , y-width  };
        DrawCarpet(a, width, grade - 1);
        a =  { x  , y-2*width  };
        DrawCarpet(a, width, grade - 1);
        a = {  x - width , y-width  };
        DrawCarpet(a, width, grade - 1);
        a = {  x - width , y -2*width };
        DrawCarpet(a, width, grade - 1);
        a = {  x -2* width , y -2*width };
        DrawCarpet(a, width, grade - 1);
        a = { x,y };

    } 
}

The type of parameter a is not array of 2 float but rather float* (because of array to pointer decay , also because your function parameter shadows the global variable).参数a的类型不是2 个float数组,而是float* (因为数组到指针衰减,也因为您的函数参数隐藏了全局变量)。 So what you're trying to do is assign two values to a pointer variable.所以你要做的是为一个指针变量分配两个值。 Try using a struct with two members as a point type instead, and pass that by reference if you want to assign to it.尝试使用具有两个成员的结构作为点类型,如果要分配给它,则通过引用传递它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM