Struct "inheritance"

Simen Kjærås simen.kjaras at gmail.com
Sun Feb 5 05:16:36 PST 2012


On Sun, 05 Feb 2012 11:58:40 +0100, Vidar Wahlberg <canidae at exent.net>  
wrote:

> Also, is this really ambiguous? Are there any cases where you can have a  
> module name followed by a parentheses, i.e. "<module>("?

Not that I know.


>  > I cannot seem to recreate this error message. Which version of the
>  > compiler are you using?
>
> I'm using gdc-4.6 (Debian 4.6.2-4).
> Using the Struct from above I can easily recreate the error:
> struct Struct {
>    int baz;
>    bool opEquals(const Struct s) const {
>      return baz == s.baz;
>    }
> }

Ah. That's the equivalent of DMD 2.054. I don't have that installed, but
it may be that this feature was not added until after that.

Fix: install GDC 4.6.1: https://bitbucket.org/goshawk/gdc/downloads

Workaround: Use a templated opEquals:

struct Struct {
     int baz;
     bool opEquals()(const Struct s) const {
         return baz == s.baz;
     }
}

Hope this works.


More information about the Digitalmars-d-learn mailing list