templates/vers2-f14/prog.cc - A program that illustrate template instantiation. | Lecture 5 - slide 33 : 40 Program 3 |
#include <iostream> #include <string> #include "point.cc" // Notice inclusion of the cc file, in order to // instantiate the template for int and double. // Else lots of linker errors will occur. // This treats templates in the same way as inline functions. // The C++ Programming Language, 4ed, page 695ff. int main(){ Point<double> pd1, pd2(1,2); Point<int> pi1, pi2(3,4); pd2.move(1,1); pi2.move(1,1), std::cout << "pd2: " << pd2 << std::endl; // (2,3) std::cout << "pi2: " << pi2 << std::endl; // (4,5) }