Calling a static method ?

andy.dwelly at safedataco.com andy.dwelly at safedataco.com
Thu Jul 13 07:50:32 PDT 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



More information about the Digitalmars-d-learn mailing list