Methods in Class

Good day everyone, I've realized hierarchy of classes: Point -> LineSegment.
It's necessary to realize the following methods of the class: moving, stretching, rotating, turning, change on an axis. I'm trying to realize moving at a some distance on this code. What should I search for in my code that it works?

[C++ Error] ClassMethods.cpp(37): E2094 'operator+' not implemented in type 'Point' for arguments of type 'int'
[C++ Error] ClassMethods.cpp(38): E2094 'operator+' not implemented in type 'Point' for arguments of type 'int'


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
46
47
48
49
50
51
52
#include <iostream.h>
#include <stdlib.h>
#include <cmath>
#include <conio.h>

// Classes
class Point
{
private:
  // Members
  double x;
  double y;

public:
  // Constructor
  Point (double _x, double _y) : x(_x), y(_y) {}
};

class LineSegment
{

friend Point operator+ (const Point &, const Point &);

private:
  // Members
  Point p1; // Bounds of the line segment
  Point p2; // Bounds of the line segment

public:
  // Constructor
  LineSegment (Point &_p1, Point &_p2) // Create a line from 2 points;
  : p1(_p1), p2(_p2)
  { }

  bool moving(LineSegment &ls) {
    int dist;
    ls.p1 = ls.p1 + dist;
    ls.p2 = ls.p2 + dist;
    return true;
  }

};

int main()
{
  Point A(1, 4), B(2, 3);
  LineSegment t1(A,B);
  
  cout << "Class hierarchy: Point -> Segment";
  
  return 0;
}
Last edited on
closed account (jvqpDjzh)
1
2
    ls.p1 = ls.p1 + dist;
    ls.p2 = ls.p2 + dist;
you are adding a integer to a Point. You have to redefine the operator+ for the class Point or make a different code logic
Last edited on
Topic archived. No new replies allowed.