固定大小数组作为函数参数:无匹配函数,可以调用到' begin'
我将固定大小数组传递给一个函数(将大小定义为函数定义中的常数)。但是,我仍然有错误
无匹配功能呼叫“开始”
# define arr_size 2
void test(int arr0[2]){
int arr1[]={1,2,3};
int arr2[arr_size];
begin(arr0); // does not work -- how can I make this work?
begin(arr1); // works
begin(arr2); // works
}
相关的讨论在这里< /a>但是,在这种情况下,阵列的大小显然并不恒定。我想避免出于效率原因避免使用向量(如在那里所建议的)。
有人知道问题是什么吗?
I am passing a fixed size array to a function (the size is defined to a constant in the function's definition). However, I still get the error
No matching function for call to 'begin'
# define arr_size 2
void test(int arr0[2]){
int arr1[]={1,2,3};
int arr2[arr_size];
begin(arr0); // does not work -- how can I make this work?
begin(arr1); // works
begin(arr2); // works
}
There is a related discussion here, however, the array's size was clearly not constant in that case. I want to avoid using vectors (as suggested there) for efficiency reasons.
Does anyone know what the issues is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此函数声明
等效于此,
因为编译器会调整具有数组类型的参数,以指示数组元素类型。
这两个声明都声明了相同的一个函数。
您甚至可以写作,例如
,您正在尝试调用函数
begin
,您可以将参数声明为对数组类型的引用
,以抑制从数组到指针的隐式转换。
This function declaration
is equivalent to
because the compiler adjusts parameters having array types to pointers to array element types.
That is the both declarations declare the same one function.
You may even write for example
So you are trying to call the function
begin
for a pointerYou could declare the parameter as a reference to the array type
to suppress the implicit conversion from an array to a pointer.