Overriden method not detected ?

chmike via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 3 13:06:50 PDT 2016


On Friday, 3 June 2016 at 15:23:16 UTC, Jonathan M Davis wrote:
Thank you for your detailed explanation.

If I have a static immutable object, I don't have to declare it 
as shared because it is implicit. Right ?

Changing my __gshared into static shared raises some errors which 
I don't know how to address. Ali's chapter doesn't address shared 
classes. May I ask for your help ?

1. question
-----------
I had a __gshared Info[N] infos_; that I fill in a static this() 
method.

How should I declare this with shared ? Is it enough to write 
static shared Info[N] infos; ? Since shared is transitive, will 
the info objects be implicitly shared ? 

2. question
-----------
As I said above, I instantiate my Info objects in a private 
static this() method. The objects are emplaced in a static shared 
void array. Since emplace only accept a void[] as argument I had 
to cast away the shared as you did in your example. The compiler 
seams happy.

However I didn't synchronized that code because I assume it is 
executed by the main thread before main starts. There is thus no 
risk of race conditions. Is this assumption correct ?


3. error
--------
A weird error is that there is apparently no overload for 
opEquals. Do I have to define one my self ? Is this so that users 
can synchronize themselves if needed ?
source/app.d(9,13): Error: none of the overloads of 'opEquals' 
are callable using argument types (shared(Info), shared(Info)), 
candidates are:
/usr/include/dmd/druntime/import/object.d(143,6):        
object.opEquals(Object lhs, Object rhs)
/usr/include/dmd/druntime/import/object.d(168,6):        
object.opEquals(const(Object) lhs, const(Object) rhs)
I guess I have to define my own opEqual.


4. error
--------
Another error is with writeln(info); where info is now a 
shared(Info).

/usr/include/dmd/phobos/std/format.d(2904,5): Error: static 
assert  "unable to format shared objects"
/usr/include/dmd/phobos/std/format.d(3477,16):        
instantiated from here: formatValue!(LockingTextWriter, 
shared(Info), char)
/usr/include/dmd/phobos/std/format.d(467,54):        instantiated 
from here: formatGeneric!(LockingTextWriter, shared(Info), char)
/usr/include/dmd/phobos/std/stdio.d(1316,31):        instantiated 
from here: formattedWrite!(LockingTextWriter, char, shared(Info))
/usr/include/dmd/phobos/std/stdio.d(3114,28):        instantiated 
from here: write!(shared(Info), char)
source/app.d(12,12):        instantiated from here: 
writeln!(shared(Info))

How can I solve that error ?





More information about the Digitalmars-d-learn mailing list