| templates/vers2-f14/prog1.cc - A program that illustrate problematic template instantiation. | Lecture 5 - slide 33 : 40 Program 4 |
#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)
string s{};
Point<std::string> ps1; // Gives rise to A LOT of complex error messages
// Point<string> is compiled, and there is a lot of problems in this class.
// Not necessarily meaningful...
ps1.move(string("a"), string("b")); // Maybe a challenge...
}