www.digitalmars.com         C & C++   DMDScript  

D - Templated Classes and Inheritance

reply resistor mac.com writes:
Alright, so I'm implementing a class called Queue (Bet you can't guess what that
one does!).  Anyways, 
Queue inherits from a class called Array, which provides an Object[] member
variable and appropriate 
accessor methods.  It also implements the Enqueue interface which defines push()
and pop() methods.

Until now, Queue has only handle Objects.  But now I've been trying to had
support for primitve types 
by means of templating.  However, I've hit a snag.

If I instantiate a Queue!(char[]), I need it to inherit from Array!(char[])
instead of Array!(Object).  Also, it 
needs to implement Enqueue!(char[]) instead of Enqueue!(Object).  Is there a
syntax to do this?  And if 
so, what is it?

Feb 24 2004
parent Sean Kelly <sean ffwd.cx> writes:
Try this:

template Queue(T) {
     class Queue : Array!(T) {}
Feb 24 2004