| templates/vers2/prog.cc - A program that illustrate template instantiation. | Lecture 6 - slide 4 : 46 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, 3ed, page 350-351.
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)
}