#include <utility> using namespace std; .. typedef pair<double, double> point; ... pair <double, double> x1; x1.first = 0; x2.second = 0; point x2{10,5}; double Distance(pair<double,double> a, point b) { double dx, dy; dx = a.first- b.first; dy = a.second - b.second; return sqrt(dx*dx + dy*dy); }
point x1{0,0}, x2{10,5}; cout << "Computing the distance from " << x1 << " to " << x2 << endl;
cout << a; // is equivalent to , but we can't call it this way. <<(cout,a); // is equivalent to , but we can't call it this way. cout << a << b; <<(<<(cout,a),b);
ostream & operator << (ostream & s, const point & p) { s << "(" << p.first <<", " << p.second << ")"; return s; }
//namespaceName::object_in_namespace string::npos
/* namespace name { // declare objects in the namespace. } */ namespace Euclid { const string D_NAME = "Euclidian"; int avar = 10; double Distance(point a, point b) { double dx, dy; dx = a.first- b.first; dy = a.second - b.second; return sqrt(dx*dx + dy*dy); } }
namespace Manhattan { const string D_NAME = "MANHATTAN"; int avar = 20; double Distance(point a, point b); } ... double Manhattan::Distance(point a, point b) { double dx, dy; dx = abs(a.first- b.first); dy = abs(a.second - b.second); return (dx + dy); }
namespace HD=Hausdorf;