Hey all, I've been slacking on my c++ for the last year and a half, and I just cannot seem to instantiating or setting up my header file correctly. I keep getting the error redefinition of void stats::updateAvg and previously defined here in my methods.cpp and class.h files. I believe my problem is that I'm not making the class object correctly, or I'm not grabbing the data correctly. Any help would be greatly appreciated thanks!
P.S. my program is very simple I'm just not used to making them with multiple files!
P.S.S. Should I put my input function out of the class in the main driver function?
I keep getting the error redefinition of void stats::updateAvg and previously defined here in my methods.cpp and class.h files. I believe my problem is that I'm not making the class object correctly, or I'm not grabbing the data correctly.
No, you're trying to define the function in both your header file and your implementation file.
Look at these snippets:
From the header:
1 2 3
void updateSum(double temp){
}
This defines (implements) the member function updateSum(). The function isn't doing anything but it is defined.
From the source file:
1 2 3 4
void stats::updateSum(double temp){
sum += temp;
}
Here you're redefining updateSum().
You can only define a function in one place.
To fix the problems you can just declare the function in the header instead of defining it: void updateSum(double temp);
I am supposed to have a header file, an implementation file and a driver file. So in my header file I should just do void updateSum(double temp); ?
I knew it was going to be something stupid. That's what I get for not keeping up on my c++ thanks guys appreciate it! I'll be sure to post on here if I have any more questions!