How to I translate this C++ structure/array

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 2 15:36:28 PDT 2015


On Saturday, 2 May 2015 at 22:01:10 UTC, WhatMeWorry wrote:
>     struct Vertex
>     {
>         vec3 position;
>         vec3 color;
>     }
>
>     Vertex triangle[6] =
>     [
>         vec3(0.0,  1.0, 0.0),
>         vec3(1.0,  0.0, 0.0),   // red
>
>        // code removed for brevity.
>     ];
>
> I keep getting the following:
>
> MeGlWindow.d(171): Error: cannot implicitly convert expression 
> (Vector([0.000000F, 1.00000F, 0.000000F])) of type 
> Vector!(float, 3) to Vertex

You have to be explicit:

     Vertex[6] triangle = /* [1] */
     [
         Vertex(
             vec3(0.0,  1.0, 0.0),
             vec3(1.0,  0.0, 0.0),   // red
         ),
         ...
     ];

[1] `Vertex triangle[6]` works, but please don't do that.


More information about the Digitalmars-d-learn mailing list