Assigning to class struct member leading to unexpected behavior.
Paul
paultjeadriaanse at gmail.com
Thu Jan 28 01:43:13 UTC 2021
I'm experiencing a compile error, but for the life of me, I
cannot figure out what is wrong.
I'll try to keep it short but the code is roughly as follows:
> class Window{
> Screen screen;
> alias screen this;
>
> this() {
> Screen s = {bottom_f: {[0, 1]}};
> this.screen = s; // Works
> this.screen = {bottom_f: {[0, 1]}}; // Leads to the
> list of errors below
> }
> ...
> }
> struct Screen{
> Vec!(2, int) bottom_f;
> ...
> }
> alias Vec(uint size, Type) = Mat!(size, 1, Type);
>
> struct Mat(uint rows, uint columns = rows, Type = float) {
> private enum uint size = rows * columns;
> union{
> Type[columns][rows] mat;
> Type[size] vec;
> }
> static if (columns == 1) alias vec this;
> else alias mat this;
> . . .
> }
List of errors:
1. "Label "bottom_f" is not used."
2. "expected ; instead of }"
3. "found `}` when expecting `;` following statement"
4. "use `{ }` for an empty statement, not `;`"
5. "found `void` when expecting `;` following statement" (later
at function below constructor)
Why would assigning to a member variable lead to errors when
using an intermediate variable of the same type does not?
I tried tweaking a lot but I just can't figure it out. Am I doing
something wrong?
More information about the Digitalmars-d-learn
mailing list