Bonjour j'aimerais faire la surcharge des opérateur += etc... et j'ai un problème.
Voilà mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #ifndef POINT_H #define POINT_H #ifndef POINT_DEBUG #define POINT_DEBUG 1 #endif #include <iostream> using namespace std ; class Point { public: // CONSTRUSTREUR Point(); Point(Point&); Point(int,int); // DESTRUSTREUR ~Point(); Point &operator+=(const Point&); void setX(int); void setY(int); int getX(); int getY(); private : int *x; int *y; }; #endifQuand je compile, j'ai cette erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
53
54
55
56
57
58 #include "point.h" Point::Point() { x = new int; y = new int; *x = 0 ; *y = 0 ; if( POINT_DEBUG ) cout << "Appel du constructeur Point(). x=" << *x << " y=" << *y << " &x=" << x << " &y=" << y << endl ; } Point::Point(int a, int b) { x = new int; y = new int ; *x = a ; *y = b; if( POINT_DEBUG ) cout << "Appel du constructeur Point(int,int). x=" << *x << " y=" << *y << " &x= " << x << " &y=" << y << endl ; } Point::Point(Point ©) { x = new int; y = new int ; *x = copy.getX(); ; *y = copy.getY() ; if( POINT_DEBUG ) cout << "Appel du constructeur Point(Point&). x=" << *x << " y=" << *y << " &x= " << x << " &y=" << y << endl ; } Point::~Point() { if( POINT_DEBUG ) cout << "Appel du destructeur ~Point()" << endl ; delete x,y ; } void Point::setX(int a) { *x = a; if( POINT_DEBUG ) cout << "Appel de la fonction setX(int). x=" << *x << endl ; } void Point::setY(int b) { *y = b; if( POINT_DEBUG ) cout << "Appel de la fonction setX(int). y=" << *y << endl ; } Point& Point::operator+=(const Point &point) { *x = point.getX(); *y = point.getY(); return *this; } int Point::getX() { return *x; } int Point::getY() { return *y; }
point.cpp:46: error: passing `const Point' as `this' argument of `int Point::getX()' discards qualifiers
point.cpp:47: error: passing `const Point' as `this' argument of `int Point::getY()' discards qualifiers
merci de votre aide
Partager