D - Templated Classes and Inheritance
- resistor mac.com (16/16) Feb 24 2004 Alright, so I'm implementing a class called Queue (Bet you can't guess w...
- Sean Kelly (4/4) Feb 24 2004 Try this:
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? Thanks, Owen
Feb 24 2004
Try this: template Queue(T) { class Queue : Array!(T) {} }
Feb 24 2004