小编use*_*479的帖子

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

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

错误: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)

c++ arrays pointers

3
推荐指数
1
解决办法
2万
查看次数

错误Nullptr未声明

所以当我在学校编译它时,nullptr错误不会出现,我认为我可以通过添加一行来修复它,当我编译它,是否有另一种方法来摆脱它,另外两个错误,我不明白为什么我得到他们都没有.有人能解释至少nullptr错误吗?

main.cpp:在函数'int main()'中:

错误:此范围内未声明'array'

错误:此范围内未声明"小时"

错误:未在此范围内声明'nullptr'

    int main()
{
    float *studentData;
    int numStudents;
    int size;
    int average = getAverage(*array, *hours);
    int median = getMedian(hours);
    int mode = getMode(hours);

    cout << "How many students were surveyed?  ";
    cin >> numStudents;
    studentData = makeArray(numStudents);

     if (studentData == nullptr)
         cout << "Error allocating memory.";
     else
     {
         getFBData(studentData, numStudents);
         selectionSort(studentData, numStudents);

         for (int i = 0; i < numStudents; i++)
             cout << *(studentData + i) << endl;

         delete[] studentData;
     }

     getAverage(*array, hours);
     printArray(size, hours); …
Run Code Online (Sandbox Code Playgroud)

c++ cmd

0
推荐指数
1
解决办法
3万
查看次数

标签 统计

c++ ×2

arrays ×1

cmd ×1

pointers ×1