fork download
  1. #include <iostream>
  2. using namespace std;
  3. class vecteur
  4. {
  5. private:
  6. float x,y;
  7. public:
  8. vecteur(float abs =0,float ord= 0);
  9. void affiche();
  10. vecteur operator + (vecteur v);
  11. };
  12. vecteur::vecteur(float abs,float ord ) {
  13. x = abs; y = ord;
  14. }
  15. void vecteur::affiche()
  16. {
  17. cout<<"x = "<< x <<" y = "<< y <<"\n"; }
  18. vecteur vecteur::operator+(vecteur v)
  19. {
  20. vecteur res;
  21. res.x = v.x + x; res.y = v.y + y;
  22. return res;
  23. }
  24. int main()
  25. {
  26. vecteur a(2,6),b(4,8),c,d,e,f;
  27. c = a + b;
  28. c.affiche();
  29. d = a.operator+(b);
  30. d.affiche();
  31. e = b.operator+(a);
  32. e.affiche();
  33. f = a + b + c;
  34. f.affiche();
  35. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
x = 6  y = 14
x = 6  y = 14
x = 6  y = 14
x = 12  y = 28