I've created toString() for a struct (which is a lot more complicated than what I've provided here) that returns a large number of concatenated strings. Here is the example:

struct Card {
    // Flesh out these enums appropriately
    CardSuit suit;
    CardValue value;
    Facing facing;

    string toString() {
        return
            this.value.toString() ~
            " of " ~
            this.suit.toString() ~
            this.suit == CardSuit.diamonds ? "" : "\t" ~
            "\tfacing " ~
            this.facing.toString();
    }
}

This code does not compile with this error message:
Error: incompatible types for ((toString(this.p_value) ~ " of " ~ toString(this.p_suit)) ~ (this.p_suit)): 'string' and 'CardSuit'

Am I using the ternary operator correctly here, or is this an issue with dmd? I'm using dmd v2.076.0.

This is the ideal way to implement this function, although I could do it other ways.

Reply via email to