Area circle and square
Aug 31, 2018 at 10:23pm UTC
I keep gettin a redefinition for Circle::Circle() error on my circle.cpp file . We were to create a program in C++ for user input of area and square. Header files were to be used. I created five files: circle.h, circle.cpp, square.h, square.cpp and main.cpp. Errors only showing up in circle.cpp.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include "Circle.h"
#define pi 3.141592
Circle::Circle()
{
radius = 1;
}
Circle::Circle(double Radius)
{
radius = Radius;
}
void Circle::setRadius(double Radius)
{
radius = Radius;
}
double Circle::getRadius()
{
return radius;
}
double Circle::getArea()
{
return (pi * radius * radius);
}
Aug 31, 2018 at 10:30pm UTC
Are you sure you haven't defined the constructor in Circle.h?
Sep 1, 2018 at 6:02am UTC
Can we see your circle.h file too?
You should have something like this in your Circle class:
1 2 3 4 5 6 7 8 9 10 11 12 13
class Circle
{
private :
double radius
public :
Circle();
Circle(double );
void setRadius(double );
double getRadius();
double getArea();
}
Maybe you forgot to define the second constructor?
EDIT: can you post the exact error you're getting?
Last edited on Sep 1, 2018 at 6:07am UTC
Sep 1, 2018 at 8:58am UTC
can you post the exact error you're getting?
If you look closely the error message most likely contains the location (file and line number) where the constructor was previously defined.
Topic archived. No new replies allowed.