"is not callable using a non-shared object"

Entity325 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 10 14:07:48 PST 2015

Usually the DMD compiler errors are very helpful, but I guess 
nothing can be perfect. In this case, I have a class I'm trying 
to declare. The class is intended to be a transport and storage 
medium, to allow information to be passed and updated 
asynchronously between two threads. One of the threads will 
periodically update, add to, or remove from the data. The other 
thread periodically checks the data. Both threads need to be able 
to run asynchronously themselves, so message passing using 
std.concurrency isn't an option. Both threads need to run in a 
loop, so the tools in std.parallelism don't work either.

My problem is: every time I try to declare a shared object in D 
from a non-shared memory space, I get a compiler error: [object] 
is not callable using a non-shared object.

This is really the only bad or ambiguous error warning I've ever 
seen in D. I've spent hours searching for information and gotten 
nothing helpful(most frustrating was the guy who responded to a 
similar inquiry with "Have you checked out std.parallelism and 
std.concurrency?" Cute. Have you tried giving actually helpful 
information instead of being clever?), so I can only assume 
what's going on. Here are the cases that I assume have produced 
the error.
1: attempting to assign a shared object to a non-shared memory 
space(easy to fix)
2: attempting to assign a non-shared object to a shared memory 
space(less easy to fix, but still not bad)
3: attempting to assign a shared object to a shared memory space 
from within a non-shared memory space(no clue)
4: attempting to create a shared object from within a non-shared 
memory space(how am I supposed to create shared objects if I 
can't do it from a non-shared space?)

And this is all assuming that I'm interpreting the error 
correctly. Again, unlike most error messages, this one is neither 
intuitive nor well-documented.

So I can get #3 and #4 to work by bypassing any sort of safety 
checks and using gross violations of object-oriented design 
philosophy, but I'd rather not do that for what I assume to be 
fairly obvious reasons.

So... basically I've tried everything I can think of to create a 
shared object from an offshoot of the Main function, but all I've 
managed to do is change which line throws the error and just how 
ambiguous the exact syntax that's causing the error is.

More information about the Digitalmars-d-learn mailing list