On Sun, 9 Aug 1998, James wrote:
> Each list holds a different type of data, i have functions to add and display
> data from these lists:
[..] 
> they all do similar things, go through the list, element by element, writing
> the data to stdout, DisplayC goes through both lists at the same time display-
> ing both data elements like this:
[..]
> can i make it so i only have 1 display and 1 add function that works for
> ALL the lists? so all i have to do is call Add with the data (the actual
> code in each add function is identical except for the list data type and
> the input data)

This is a good question, one the creator of C++ asked himself ~10 years
ago.  I recommend picking up a good book on the topic and examining the
topics "derived classes" and "virtual functions".

You can, of course, do this in C, but it rarely looks very pretty.  The
Linux kernel itself is probably the most elegant C-based implementation of
this that I've come across.

Adam

Reply via email to