toHash() and Interfaces
Steven Schveighoffer
schveiguy at yahoo.com
Fri May 6 05:02:58 PDT 2011
On Thu, 05 May 2011 17:03:51 -0400, Nrgyzer <nrgyzer at gmail.com> wrote:
> Hey guys,
>
> I'm trying to call toHash() in a class which receives an interface
> class as input param. But I always get "Error: no property 'toHash'
> for type...".
>
> My code looks like:
>
> module iFBlock;
>
> private {
> import std.stream;
> }
>
> interface IFBlock {
> public {
> void write(Stream);
> }
> }
>
> module myFile;
>
> private {
> import iFBlock;
> }
>
> class MyFile {
> private {
> IFBlock[hash_t] pBlocks;
> }
> public {
> void addBlock(IFBlock b) {
> pBlocks[b.toHash()] = b;
> }
> }
> }
>
> Is there any chance to get the hash of the FBlock-interface?
(cast(Object)b).toHash()
D has this horrible notion that any interface can be for a COM object,
even though COM interfaces can only inherit from IUnknown (known
statically). Therefore, interfaces that don't inherit from IUnknown are
not considered Objects, even though they could and should be.
So you have to manually cast an interface to Object in order to call an
Object function.
-Steve
More information about the Digitalmars-d-learn
mailing list