c++ - Question about code re-use (Template or Inheritance) -
i wrote link list class , besides type of cur object can handle now.
i'm interested in reusing code can handle object.
i thinking maybe this? right current classes truck , events , have linklist class. using linklist class it's right setup events, trucks have same kinda behavior in linklist few minors changes list. instead of copying , reusing that. setup both truck , events item? item base class , truck , events inherit item. can pass in truck , event list items, work?
or templatize list?
a template definitely right choice. of who've been around since before templates available can attest superiority on alternatives.
of course, unless have overwhelming reason write own, you're better off using std::list
(or, perhaps, boost slist
).
Comments
Post a Comment