不兼容的类型在“int”分配到“INT [(((sizetype)(((ssizetype)M)-1))1)]” [英] incompatible types in assignment of ‘int’ to ‘int [(((sizetype)(((ssizetype)m) -1)) 1)]’
本文介绍了不兼容的类型在“int”分配到“INT [(((sizetype)(((ssizetype)M)-1))1)]”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的C code给出了一个错误:
The following C code gives an error:
incompatible types in assignment of ‘int’ to
‘int [(((sizetype)(((ssizetype)m) -1)) 1)]’
在这里我所说的递归函数的行:
On the lines where I call the recursive functions:
int mergeSort(int arr[], int n)
{
if (n > 1) {
int m = (int)(n / 2);
int A1[m]; // array 1 --> 1 TO M
int A2[n-m]; // array 2 --> M + 1 TO N
int temp = m+1;
for (int i = 0; i < n; i++) {
if (i == m) break;
A1[i] = arr[i];
A2[i] = arr[temp++];
}
A1 = mergeSort(A1, m); //error happens here, assigning an
//integer into an integer array.
A2 = mergeSort(A2, n - m);
arr = merge(A1, A2);
}
return arr;
}
这个错误是什么意思?
What does this error mean?
推荐答案
有几个误区:
- C ++不支持可变长度阵列(
A1 [M]
) - 使用的std ::矢量
来代替。 - 即使它,数组不能被重新分配,所以
A1 = ...
是非法的 - 即使他们可以,你不能指定单个
INT
给他们。归并
返回INT
(为什么?)
- C++ doesn't support variable length arrays (
A1[m]
) - use astd::vector
instead. - even if it did, arrays can't be reassigned, so
A1 =...
is illegal - even if they could, you couldn't assign a single
int
to them.mergeSort
returns anint
(why is that?)
这篇关于不兼容的类型在“int”分配到“INT [(((sizetype)(((ssizetype)M)-1))1)]”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文