fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class object_c {
  5.  
  6. public:
  7. int x,
  8. y;
  9.  
  10. object_c(int X, int Y) : x (X), y (Y){}
  11. };
  12.  
  13. class calc_c {
  14. private:
  15. object_c *ship,
  16. *targ,
  17. *ref;
  18.  
  19. public:
  20. int pos2 (object_c A, object_c B) {
  21. return (A.x-B.x)*(A.x-B.x);
  22. }
  23. int ship_pos (object_c A){return pos2(*ship, A);} //these
  24. int ship_targ_pos () {return pos2(*ship, *targ);}//should be
  25. int ship_ref_pos () {return pos2(*ship, *ref);} //replaced
  26.  
  27. void set_ship (object_c *A){ship = A;}
  28. void set_targ (object_c *A){targ = A;}
  29. void set_ref (object_c *A){ref = A;}
  30. } calc;
  31.  
  32. int main() {
  33.  
  34. object_c Ship(0,1), Targ(10,11), Ref(20,21); //notice capitalization
  35.  
  36. calc.set_ship(&Ship);
  37. calc.set_targ(&Targ);
  38. calc.set_ref (&Ref);
  39.  
  40. cout << calc.pos2 (Ship, Targ)<< endl;//should
  41. cout << calc.ship_pos (Targ) << endl;//be
  42. cout << calc.ship_targ_pos () << endl;//identical
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
100
100
100