Topic: typedef under inheritance


Author: rsahu@unm.edu (Raikanta Sahu)
Date: 25 Aug 1994 12:31:04 -0600
Raw View
I was trying to make a generic linked list base class. I was thinking
for example, that I could make objects of int linked list and double
linked list by dering from the generic linked list.

The problem I am facing is this. The linked list need to have some value
in each link. An int linked list must have an int, a double linked list
must have a double, and so forth. The functions associated with the
linked list, like add(), replace(), remove() don't change much. However,
the arguments to these functions need change. I was thinking I could
overcome this difficulty by a typedef.

In the list class I could have


typedef int mem ;

In the double list class I could have

typedef double mem ;

etc.

The add fuction can be declared like :

add(mem &) ;

My idea was that if I tried to add a double to an object of double list
class, the add function would be invoked with mem := double. But it is
not.

How can I get around this problem ??

Thanks.

-Raikanta
rsahu@argo.unm.edu