Thread overview
Calling a static method ?
Jul 13, 2006
andy.dwelly
Jul 13, 2006
Brad Anderson
Jul 13, 2006
Lars Ivar Igesund
Jul 13, 2006
Andy Dwelly
Jul 13, 2006
Brad Anderson
July 13, 2006
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
July 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 Dwelly

have you tried to add:

module EventQueue;

to the first file?

BA
July 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 Dwelly

Hmm, 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
July 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 ?


July 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