▁in ▁C ++, ▁this ▁dup lication ▁of ▁code ▁can ▁be ▁circum vent ed ▁by ▁defining ▁a ▁class ▁template : ▁template ▁< typename ▁T > ▁class ▁List ▁{ ▁▁ ▁// ▁Class ▁contents . ▁}; ▁ ▁List < An imal > ▁list _ of _ anim als ; ▁List < Car > ▁list _ of _ c ars ; ▁A bove , ▁T ▁is ▁a ▁placeholder ▁for ▁whatever ▁type ▁is ▁specified ▁when ▁the ▁list ▁is ▁created . ▁These ▁" cont ain ers - of - type - T ", ▁commonly ▁called ▁templates , ▁allow ▁a ▁class ▁to ▁be ▁re used ▁with ▁different ▁dat at ypes ▁as ▁long ▁as ▁certain ▁contract s ▁such ▁as ▁sub types ▁and ▁signature ▁are ▁kept . ▁This ▁generic ity ▁mechanism ▁should ▁not ▁be ▁confused ▁with ▁inclusion ▁polym orphism , ▁which ▁is ▁the ▁algorithm ic ▁usage ▁of ▁exchange able ▁sub - classes : ▁for ▁instance , ▁a ▁list ▁of ▁objects ▁of ▁type ▁Mov ing _ Object ▁containing ▁objects ▁of ▁type ▁Animal ▁and ▁Car . ▁Tem plates ▁can ▁also ▁be ▁used ▁for ▁type - in dependent ▁functions ▁as ▁in ▁the ▁Sw ap ▁example ▁below : ▁ ▁// ▁" & " ▁passes ▁parameters ▁by ▁reference ▁template ▁< typename ▁T > ▁void ▁Sw ap ( T & ▁a , ▁T & ▁b ) ▁{ ▁▁ ▁T ▁temp ▁= ▁b ; ▁▁ ▁b ▁= ▁a ; ▁▁ ▁a ▁= ▁temp ; ▁} ▁ ▁std :: string ▁hello ▁= ▁" World ! "; ▁std :: string ▁world ▁= ▁" Hello , ▁"; ▁Sw ap ( world ,