Constructor Error

I'm a beginner and need help finding a solution to this constructor problem I'm having. My code is as follows:

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cmath>
 
using namespace std;

class Distance
{
    double x1, y1, x2, y2;
     
    public:
      double  setx1;
      double  sety1;
      double  setx2;
      double  sety2;
 
            
     //Constructor
         
    Coordinates(double CoorX1, double CoorY1, double CoorX2, double CoorY2)
        {
            CoorX1 =x1;
            CoorY1 =y1;
            CoorX2 =x2;
            CoorY2 =y2;
        }
       
     //Function that calculates distance 
      double GetDistance()
        {
             double Pow1, Pow2, Distance;
    
    		 Pow1 = pow((x1-x2),2.0);
    		 Pow2 = pow((y1-y2),2.0);
    		 Distance = sqrt(Pow1 + Pow2);
    	    
           cout<<x1;
             return Distance;
        }
    
    //Get functions
      double  GetX1() {return x1;}
      double  GetY1() {return y1;}
      double  GetX2() {return x2;}
      double  GetY2() {return y2;}
};



The Error message I am recieving is:

main.cpp:26:75: error: ISO C++ forbids declaration of 'Coordinates' with no type [-fpermissive]


Any solutions?! Thanks!!
closed account (Dy7SLyTq)
constructors have to be the same name as the class
There was no mention of that made in my book. WTF. It works. Thanks!!
Last edited on
closed account (Dy7SLyTq)
np. fyi if you do python the constructors all have the name init()
Thanks I'll keep that in mind!
1
2
3
4
CoorX1 =x1;
            CoorY1 =y1;
            CoorX2 =x2;
            CoorY2 =y2;


also change it to

1
2
3
4
x1 = CoorX1 
....
....
....

while constructing the object
Last edited on
Topic archived. No new replies allowed.