执行以下代码时,执行功能更改时会出现上述错误。我没有使用过任何解除引用,也没有在任何地方使用过void *。起初我认为这是因为(double *)malloc(..)但即使使用静态内存分配问题仍然存在。另外,编译器说max_element不是std ::或&#34的成员;错误:' max_element'未在此范围内宣布"
#include <iostream>
#include <cmath>
#include <tgmath.h>
#include <vector>
#include <stdio.h>
using namespace std;
struct Exchange{
int nHalf ;
int nThird ;
int nFourht ;
int amDollars[3] ;
};
void change (double n, Exchange& a) ;
// Main function for the program
int main( )
{
int i = 0 ;
vector <int> n ;
n.reserve(10) ;
vector<Exchange>coin ;
coin.reserve(10) ;
// n = (double *) malloc(sizeof(double)) ;
do{
cin >> n[i] ;
change (n[i], coin[i]) ;
coin[i].amDollars[0] =
coin[i].nHalf + coin[i].nThird + coin[i].nFourht ;
coin[i].amDollars[1] = n[i] ;
coin[i].amDollars[2] = 0 ;
cout << *max_element(&coin[i].amDollars[0], &coin[i].amDollars[2]) << endl ;
i++ ;
}while (i < 10) ;
return 0;
}
void change (double n, Exchange& a) {
a.nHalf = trunc(n/2) ;
a.nThird = trunc(n/3) ;
a.nFourht = trunc(n/4) ;
}