digitalmars.D.learn - Impishly stupid template question
- Jeremy Gibson (14/14) Jun 20 2006 I have a medium-weight queue class which I created some time in November...
- John Demme (20/40) Jun 20 2006 Unfortunately, DMD's template error messages suck it big-time. I assume
- Jeremy Gibson (3/7) Jun 20 2006 Those are the only error messages I'm getting, unfortunately, but I'll s...
- Jeremy Gibson (18/25) Jun 21 2006 After further testing, using /+ +/ comments to block out the ENTIRE cont...
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.?
Jun 20 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 teqdruid.com http://www.teqdruid.com/
Jun 20 2006
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.Those are the only error messages I'm getting, unfortunately, but I'll see what's what in the queue module. Sleep is more appealing than debugging right now, so I'll have to look into it in the morning... =)
Jun 20 2006
In article <e7apdv$1kkd$1 digitaldaemon.com>, Jeremy Gibson <jtgibson telus net> says...After further testing, using /+ +/ comments to block out the ENTIRE contents of the queue class, as well as removing all derived classes (stacks and pools) from the queue module, I still suffered from these errors: alliance.d(74): template instance queue is not a template declaration, it is a i mport alliance.d(74): queue!(ac_event) is used as a type alliance.d(74): variable alliance.alliance.ac_game.event_queue voids have no val ue The problem, as the cryptic error message hinted at, was a name conflict between the module "queue" and the class template name "queue". I wanted to keep the queue as a portable module for use in my other projects, but went ahead and renamed the queue class to "ac_queue" for consistency with my other classes in the project -- not surprisingly, everything then compiled perfectly (working perfectly is another matter... I still have to write a test suite!). I'll have to think up of a good alternate name for the module and/or class when I add it to my code library.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.Those are the only error messages I'm getting, unfortunately, but I'll see what's what in the queue module. Sleep is more appealing than debugging right now, so I'll have to look into it in the morning... =)
Jun 21 2006