Goldman Sachs Interview Question
Software Engineer / DevelopersTemplates are useful when a specific bahaviour (or say a ds with some functionality) is independent of data type on which it operates.
Whereas inheritance is useful when a)code reuse b)more specifically (as in case of polymorphism) you want to have different specific behaviour with a generic name for the behaviour.
Template is good if you want to use your container for multiple class
- one2free December 06, 2007template <class T>
class List{
};
class contact{
};
list<contact> agenda;
Inheritance is good when you want to restrict your container to store only this class of object
class Agenda : public List <contact>