Skip to content

Instantly share code, notes, and snippets.

@pmelanson
Last active December 10, 2015 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmelanson/4370578 to your computer and use it in GitHub Desktop.
Save pmelanson/4370578 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class object_c {
public:
int x,
y;
object_c(int X, int Y) : x (X), y (Y){}
};
class calc_c {
private:
object_c *ship,
*targ,
*ref;
public:
int pos2 (object_c A, object_c B) {
return (A.x-B.x)*(A.x-B.x);
}
int ship_pos (object_c A){return pos2(*ship, A);} //these
int ship_targ_pos () {return pos2(*ship, *targ);}//should be
int ship_ref_pos () {return pos2(*ship, *ref);} //replaced
void set_ship (object_c *A){ship = A;}
void set_targ (object_c *A){targ = A;}
void set_ref (object_c *A){ref = A;}
} calc;
int main() {
object_c Ship(0,1), Targ(10,11), Ref(20,21); //notice capitalization
calc.set_ship(&Ship);
calc.set_targ(&Targ);
calc.set_ref (&Ref);
cout << calc.pos2 (Ship, Targ)<< endl;//should
cout << calc.ship_pos (Targ) << endl;//be
cout << calc.ship_targ_pos () << endl;//identical
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment