Hi,

I have some issues with struct initializer and alias this.
In following example 1 and 2 is working but there is a syntax
error for 3. I think as case 2 is working case 3 should work also.
For me case 3 is looking much nicer than case 1.
What do you think?

void main()
{
        // Working
        Request request1 = {
                definitions: {[
                        Definition("A", "B")
                ]}
        };
        
        // Working
        Request request2;
        request2.definitions = [Definition()];
        
// cannot implicitly convert expression ([Definition("A", "B")]) of type Definition[] to Definitions
        Request request3 = {
                definitions: [
                        Definition("A", "B")
                ]
        };
}

struct Request
{
        Definitions definitions;
}

struct Definitions
{
    private Definition[] _arr;
    alias values this;
    @property Definition[] values(){return _arr;}
    @property void values(Definition[] values){_arr = values;}
}

struct Definition
{
    string attributeName;
    string attributeType;
}

Kind regards
André

Reply via email to