错误:一元'*'的无效类型参数

use*_*479 3 c++ arrays pointers

我不明白这些错误可以解释一下吗?

错误:unary' '(有'double')错误的无效类型参数:unary' '的无效类型参数 '(有'double')错误:unary'*'的无效类型参数(有'double')

    double getMedian(double *array, int *hours){
    if (*hours <= 0) return 0;
    if (*hours % 2) return (float)*array[(*hours + 1) / 2];
    else{int pos = *hours / 2;
    return (float)(*array[pos] + *array[pos + 1]) / 2;}}
Run Code Online (Sandbox Code Playgroud)

ppl*_*ppl 6

您已经array[]运营商解除引用.你想要的是:

double getMedian(double *array, int *hours){
if (*hours <= 0) return 0;
if (*hours % 2) return (float)array[(*hours + 1) / 2];
else{int pos = *hours / 2;
return (float)(array[pos] + array[pos + 1]) / 2;}}
Run Code Online (Sandbox Code Playgroud)

请注意,写作x[y]是简写*(x + (y)).在您的代码中,您基本上具有相应的**array.