//circlemain.cpp
#include <iostream>
#include "Circleheader.h"
usingnamespace std;
int main ()
{
double temp = 0.0;
Circle r1(3 );
Circle cAnswer;
cAnswer = r1.GetCircumference(3);
cout << "Circumference = " << temp << endl;
cAnswer = r1.GetArea(3);
cout << "Area = " << temp << endl;
cout << "Answers should be 18.84 and 28.27." << endl;
return 1;
}
Which gives output:
circle.cpp: In member function ‘Circle Circle::GetCircumference(Circle)’:
circle.cpp:22: error: no match for ‘operator*’ in ‘2 * Radius’
circle.cpp: In member function ‘Circle Circle::GetArea(Circle)’:
circle.cpp:31: error: no match for ‘operator*’ in ‘Radius * Radius’
I've been playing with this for about 2 hours now. Before, the code would compile but it wasn't getting the Radius argument to the methods, so the output would just be 0 from both. I'm not sure where to go from here.
You choose very bad names for your variables, data members and parameters.
The compiler gets confused because you use the same name for float Radius which is a data member of Circle, and Circle Radius which is a parameter of your GetArea() and GetCircumference() functions.
My apologies, for originally replying while not 100% focused.
When you write member functions, like you do for the Circle class, you write them for the currentCircle. You don't write them for other Circles. So you don't pass them as parameters.
For instance Circle::GetArea().
You use that to ask a Circle "hey what's your area?", and the Circle replies by using its ownRadius in the calculations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// return a float value, not a Circle,
// no parameters; we work on our current Circle's data,
float Circle::GetArea()
{
return Radius * Radius * Pi;
}
// ...
int main()
{
Circle c(3);
cout << "Area of Circle c is: " << c.GetArea() << endl;
}
Yeah. I think I actually solved this one on a different problem. My test wanted me to find the volume and mass of a sphere of any radius and density. Starting fresh helped. Thanks for the corrections!