When executing the following code I get the above mentioned error when function change is executed. I have not used any dereferencing nor have used void* anywhere. At first I thought it was because of (double *) malloc(..) but even upon using static memory allocation the problem still holds. Additionally, compiler says that max_element is not a member of std:: or "error: 'max_element' was not declared in this scope"
#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) ;
}
Very likely that first error is produced by tgmath.h . Try to replace it with ctgmath
. Or, if you doesn't need to operate with complex numbers, just use cmath
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.