Expression must have (Pointer-to-) function type while using structs

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error Expression must have (Pointer-to-) function type while using structs on this date .

So basically what I’m doing is passing an array of structs from one function to another function. It works for the show functions, but not for the max functions :/ What exactly am i doing wrong?

void show( const ABC & x ){
    cout<<"{"<<x.n<<",'"<<x.c<<"',{"<<x.a[0]<<","<<x.a[1]<<","<<x.a[2]<<"}}";
}

void show( const ABC arr[], unsigned elements ){
    for(unsigned i=0; i<elements; i++)
        show(arr[i]);
}

the following doesn’t work

double max( const ABC & x ){
    double max=x.a[2];
    if(x.a[1]>max)
        max=x.a[1];
    if(x.a[0]>max)
        max=x.a[0];
    return max;
}

double max( const ABC arr[], unsigned elements ){
    double max=arr[2].a[3];
    for(unsigned i=0; i<elements; i++)
        if(max<max(arr[i])){
            max=max(arr[i]);
        }
    return max;
}

Answer

Rename your double variable to something else than max. As things are, it is hiding the functions that share the same name, hence why the call expression is invalid (you’re trying to pass arguments to a double).