Impishly stupid template question

John Demme me at teqdruid.com
Tue Jun 20 23:11:29 PDT 2006


Jeremy Gibson wrote:

> I have a medium-weight queue class which I created some time in November
> or December for general use, but never actually went ahead and tried using
> it until
> now.  The queue class is a class template.
> 
> In C++, it's possible to create a member variable of template class: for
> instance, "vector<int> coordinates", "vector<ObjectClass*> objectTable",
> etc.
> 
> In D, what is the equivalent?  I tried using "queue!(ac_event)
> event_queue" as a member variable, but I'm getting compile errors:
> 
> alliance.d(74): class queue.queue(var_type) is used as a type
> alliance.d(74): variable alliance.alliance.ac_game.event_queue voids have
> no val ue
> 
> I know that templates in D have to be instantiated to be of use, so I'm
> wondering how I can tell D that I want the event_queue variable to
> indicate an instantiated queue of ac_event objects... what type do I need
> to assign to the member variable, etc.?

Unfortunately, DMD's template error messages suck it big-time.  I assume
that you're trying to do something similar to:
class CT(A) {
        A a;
}

class Y {
        CT!(Y) cty;
}

void main() {
}

That example compiles.  The error message you got appears whenever there's
_any_ issue with the template.  Chances are something else is up- look for
other error messages.  I've found that in any D program with templates,
only the first one or two error messages are worth anything.

Hope that helps!

-- 
~John Demme
me at teqdruid.com
http://www.teqdruid.com/



More information about the Digitalmars-d-learn mailing list