Interface problems

Mandeep Singh Brar mandeep at brars.co.in
Tue Jan 25 21:12:32 PST 2011


Mandeep Singh Brar:

> I am not able to:
>
> - find indexOf interface in an interface range using std.algorithm.

> I don't understand. Please explain better.

In the following snippet:
     Interface interfaceA{}
     class C:interfaceA{}
     class D:interfaceA{}

     interfaceA[] registry;
     register(interfaceA a) { registry ~= a; }
     unregister(interfaceA a) {idx = registry.indexOf(a); registry.replace(idx,
idx+1, null); }
In the above statement indexOf does not work.

> - compare interface objects

> What kind of comparisons do you need to perform and why?

Simple comparisons like in the below snippet
      class A {
          interfaceTest myInstance;
          setInstance(interfaceTest interfaceInstance) {
                 if(myInstance != interfaceInstance) //does not work
                 {
                      updateMyInstance;
                      doStuff;
                 }
          }
      }


> - assign interface to generic objects.

> Why do you need to do this?

      Just store various types of objects in a generic way like
           Object[] objects;
           objects ~= objA; objects~= interB and so on.

      I cant use Variant because interface can not be assigned to Variants and i
cant use Objects too.

> Bye,
> bearophile

Thanks
Mandeep


More information about the Digitalmars-d-learn mailing list