digitalmars.D.learn - Calling a static method ?
- andy.dwelly safedataco.com (36/36) Jul 13 2006 I'm taking a first look at D. I have a singleton class:
- Brad Anderson (5/58) Jul 13 2006 have you tried to add:
- Lars Ivar Igesund (11/64) Jul 13 2006 Hmm, the problem here is that the module is named EventQueue too. You ca...
- Andy Dwelly (5/5) Jul 13 2006 Ah. Modules are a topic I haven't tackled yet.
- Brad Anderson (2/12) Jul 13 2006 http://www.digitalmars.com/d/module.html
I'm taking a first look at D. I have a singleton class: class EventQueue { private static EventQueue _instance; private this() { } public static EventQueue instance() { if (_instance is null) { _instance = new EventQueue; } return _instance; } } int main(char[][] args) { auto var = EventQueue.instance(); return 0; } which compiles quite happiliy (WinXP, dmd 0.162) with dmd -c EventQueue.d , I have another file Frame.d: import Component; import EventQueue; class Frame: Component { private EventQueue _queue; private this(char[] title) { EventQueue q = EventQueue.instance; } public void add(Component c) { } } ..which is trying to create an event queue. When I compile this with dmd -c Frame.d I get an: Frame.d(19): undefined identifier module EventQueue.instance What am I doing wrong here ? The fact that the main function in the EventQueue.d file suggests that its some kind of linker or import error, the instance() method in EventQueue seems to be OK. Can somebody give me some guidance please. Andy Dwelly
Jul 13 2006
andy.dwelly safedataco.com wrote:I'm taking a first look at D. I have a singleton class: class EventQueue { private static EventQueue _instance; private this() { } public static EventQueue instance() { if (_instance is null) { _instance = new EventQueue; } return _instance; } } int main(char[][] args) { auto var = EventQueue.instance(); return 0; } which compiles quite happiliy (WinXP, dmd 0.162) with dmd -c EventQueue.d , I have another file Frame.d: import Component; import EventQueue; class Frame: Component { private EventQueue _queue; private this(char[] title) { EventQueue q = EventQueue.instance; } public void add(Component c) { } } ..which is trying to create an event queue. When I compile this with dmd -c Frame.d I get an: Frame.d(19): undefined identifier module EventQueue.instance What am I doing wrong here ? The fact that the main function in the EventQueue.d file suggests that its some kind of linker or import error, the instance() method in EventQueue seems to be OK. Can somebody give me some guidance please. Andy Dwellyhave you tried to add: module EventQueue; to the first file? BA
Jul 13 2006
andy.dwelly safedataco.com wrote:I'm taking a first look at D. I have a singleton class: class EventQueue { private static EventQueue _instance; private this() { } public static EventQueue instance() { if (_instance is null) { _instance = new EventQueue; } return _instance; } } int main(char[][] args) { auto var = EventQueue.instance(); return 0; } which compiles quite happiliy (WinXP, dmd 0.162) with dmd -c EventQueue.d , I have another file Frame.d: import Component; import EventQueue; class Frame: Component { private EventQueue _queue; private this(char[] title) { EventQueue q = EventQueue.instance; } public void add(Component c) { } } ..which is trying to create an event queue. When I compile this with dmd -c Frame.d I get an: Frame.d(19): undefined identifier module EventQueue.instance What am I doing wrong here ? The fact that the main function in the EventQueue.d file suggests that its some kind of linker or import error, the instance() method in EventQueue seems to be OK. Can somebody give me some guidance please. Andy DwellyHmm, the problem here is that the module is named EventQueue too. You can try to add () to your instance invocation in Frame and see if that helps, otherwise you can change the module name (and filename) to lowercase. If you want this to be in a larger project, you might want to add an extra level to your hierarchy, such that the module name becomes myproject.EventQueue. -- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivi
Jul 13 2006
Ah. Modules are a topic I haven't tackled yet. Changing the filenames to lower case and the imports as well fixes this. So modules contain classes and functions, and import, imports modules - is that how it works ? Is there any documentation covering this anywhere ?
Jul 13 2006
Andy Dwelly wrote:Ah. Modules are a topic I haven't tackled yet. Changing the filenames to lower case and the imports as well fixes this. So modules contain classes and functions, and import, imports modules - is that how it works ? Is there any documentation covering this anywhere ?http://www.digitalmars.com/d/module.html
Jul 13 2006