_Beyond C++ Templates_ by Fred Wild Example 1: (a) #define max(a,b) (((a) > (b)) ? (a) : (b)) (b) int larger ; larger = max(item1, item2) ; /* before preprocessing */ (c) int larger ; larger = (((item1) > (item2)) ? (item1) : (item2)); /* after preprocessing */ Example 2: (a) #define MAKELISTCLASS(listname,itemtype) \ class listname { \ public: \ ... \ void AddItem (itemtype theItem); \ void RemoveItem (itemtype theItem); \ } ; \ \ inline listname##::AddItem (itemtype theItem) ... \ \ inline listname##::RemoveItem (itemtype theItem) ... \ (b) MAKELISTCLASS (NameList, String) ... NameList students ; ... students.AddItem("Jane"); ... Example 3: (a) template class List { public: ... void AddItem (T theItem); void RemoveItem (T theItem); } ; template List::AddItem (T theItem) ... template List::RemoveItem (T theItem) ... (b) List students ; ... students.AddItem ("Jane"); ... Example 4: (a) #define StrList List (b) StrList students ; ... students.AddItem("Jane") ; Example 5: (a) object PetOwner Name : String ; Pets : list_of Pet ; end ; object Pet PetKind : String ; MyOwner : ptr_to PetOwner ; end ; (b) ... # create a constructor for each object .each_obj # output the constructor function signature and opening brace :::() :{ # if the object has any 'list_of' attributes, output code # to clear the list .each_attr : .Clear(); .end # if the object has any 'ptr_to' attributes, set them to NULL .each_attr : = NULL ; .end # add a closing brace, and a trailing blank line :} : .end # .each_obj ...