I am working in C++, making a pretty simple function that is supposed to calculate the standard deviation of a given number entered by the user. But when I try to use the sqrt
function with my variable mean
, there is an error I get when attempting to compile my program:
'void*' is not a pointer-to-object type
Below is my code, as well as a picture of the error message.
#include <iostream>
#include <tgmath.h>
#include "stddev.h" //this is just a seperate header file that I have going with my program
using namespace std;
void stats (float *data, int n){
float mean = 0;
int i;
for (i = 0; i < n; i++){
mean += data[i];
}
mean = mean / n;
for(i = 0; i < n; i++) { //subtracting the mean from the number and squaring the result.
data[i] = data[i] - mean;
data[i] = data[i] * data[i];
}
mean = 0;
for (i = 0; i < n; i++){
mean += data[i];
}
mean = mean / n;
float stdDeviation = sqrt(mean); //Here is where I get the error
cout << "\t Your Standard Deviation is : " << stdDeviation << endl;
}
Use of <tgmath.h>
(or <ctgmath>
) is deprecated in C++.
It's supposed to still work -- <tgmath.h>
is meant to be exactly equivalent to including <cmath>
and <complex>
-- so you are looking at a compiler/library bug. But perhaps this is something that the vendors are not really interested in putting time into fixing since it is deprecated.
Things should go more smoothly to use #include <cmath>
instead of #include <tgmath.h>
.
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.