20-CS-4003-001 Organization of Programming Languages Fall 2017
Virtual Functions and Templates

Lambda calculus, Type theory, Formal semantics, Program analysis

Templates alone is not enough

Archive:
   
template.tar     All the code and documentation in a tar file
   
Makefile:
   
Makefile     Make all the code below with this
   
Code:
   
vir7.cc     Create a vector like this:
 
   vector<Person*> *queue = new vector<Person*>;
 
and insert into queue objects of three different classes, all of which subclass Person. Then apply getName() and getRank() and setRank() to each object as it is taken from the queue. The virtual declarations in class Person ensures the output is as expected.
   
vir8.cc     Same code as vir7.cc but without the functions in Person declared as virtual. Disaster.