写新的值到数组 [英] Writing new values into array
本文介绍了写新的值到数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的code的片段:
This is a fragment of my code:
typedef float point2[2];
point2 a = {-90, -90};
point2 b = {-90, 90};
point2 c = {90, 90};
point2 d = {90, -90};
glBegin(GL_POLYGON);
glVertex2fv(a);
glVertex2fv(b);
glVertex2fv(c);
glVertex2fv(d);
glEnd();
这也同样非常好。但后来当我尝试新的值写入到这些阵列,如:
And this goes really well. But later when I try to write new values into these arrays, like:
a = {-66, -66};
b = {-66, 66};
在这里,我得到一个错误:结果
And here I get an error:
error: assigning to an array from an initializer list
和我理解,我不能直接将值分配给其声明之后的数组。但是,这个应该怎么样子?
And I understand, that I can't assign values directly to an array after its declaration. But how this should looks like?
推荐答案
您不能分配到使用初始化列表的数组。但是,如果你使用 的std ::阵列
,而不是C数组那么这是可能的:
You can't assign to an array using an initializer list. But if you use std::array
instead of a C array then this is possible:
#include <array>
typedef std::array<float, 2> point2;
point2 a = {-90.0, -90.0};
a = {-66, -66};
和你仍然可以把它传递给像 glVertex2fv
功能,通过使用的 的std ::数组::数据
:
And you can still pass it to a function like glVertex2fv
that takes a pointer to an array by using std::array::data
:
glVertex2fv(a.data());
这篇关于写新的值到数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文