Hi,
I have edited and re-edited my code but this error never seems to go away:
The error is:
error: re-definition of 'rectangle::rectangle(double, double)'
Here's my class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#ifndef RECTANGLE_H
#define RECTANGLE_H
class rectangle
{
private:
double length, width; //private member variables
public:
rectangle() = default; //constructor
rectangle(double x, double y):length(x),width(y){}
double area();
double perimeter();
double diagonal();
};
#endif // RECTANGLE_H
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include "rectangle.h"
#include <cmath>
using namespace std;
rectangle::rectangle(double x, double y)
{
length = x;
width = y;
}
double rectangle::area(){
return length*width;
}
double rectangle::perimeter(){
return 2*(length * width);
}
double rectangle::diagonal(){
return hypot(length,width);
}
|
Here's my main function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
#include "rectangle.h"
using namespace std;
int main(){
rectangle rect(4.0,4.0);
cout<<rect.area()<<endl;
cout<<rect.perimeter()<<endl;
return 0;
}
|
Last edited on
You've implemented rectangle::rectangle(double, double) twice. Remove one of them.