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
| class Point
{
int x, y;
public:
void deplace(int dx, int dy) {x+= dx; y+=dy;}
Point (int x=10, int y=20) {}//Constructeur par défaut
~Point(){}
Point(const Point& p){x=p.x; y=p.y;}
Point& operator= (const Point& p){x=p.x; y=p.y;}
};
class Cercle
{
Point* centre;
unsigned rayon;
public:
void deplace(int dx, int dy) {(*centre).deplace (dx, dy);}
Cercle(Point* p=&Point(0,1), unsigned r=0){}
Cercle(const Cercle& c) {(*this).centre = c.centre; rayon=c.rayon;}
Cercle& operator= (const Cercle& c)
{
(*this).centre = c.centre; rayon = c.rayon;
return *this;
}
void affect(Point* p){(*this).centre=p;}
};
int main()
{
Point p1(10, 20);
Cercle c1, c2;
c1.affect(&p1);
Cercle c3 = c1;
Point p2;
c1 = c2;
c1.deplace(-5, 3);
return 0;
} |
Partager