![]() ![]() ![]() ![]() | A sample application. | Lecture 5 - slide 9 : 39 Program 4 |
// Ilustration of class point parameterized with a "policy type" #include <iostream> #include <string> #include "point.cc" #include "norms.cc" template<typename C>void do_tell_about(C x, C y){ double dist = x.distance_to(y); std::cout << "Distance: " << dist << std::endl; std::cout << "Less than? " << (x.less_than(y) ? "true" : "false") << std::endl << std::endl; } int main(){ using namespace std; double dist; Point<FixedNorm> p1(1,2), // Here we parameterize p1 and p2 with a bundle of functions from Fixed form. p2(4,11); do_tell_about(p1,p2); Point<HorizontalNorm> p3(1,2), // Ditto p3 and p4 with HorizontalNorm p4(4,11); do_tell_about(p3,p4); Point<VerticalNorm> p5(1,2), // Ditto p5 and p6 with VerticalNorm p6(4,11); do_tell_about(p5,p6); Point<Norm> p7(1,2), // Ditto p7 and p8 with Norm p8(4,11); do_tell_about(p7,p8); }