Detect uninitialized class var access

wjoe invalid at example.com
Mon Sep 26 16:22:02 UTC 2022


On Sunday, 25 September 2022 at 02:10:00 UTC, Salih Dincer wrote:
> On Saturday, 24 September 2022 at 13:17:19 UTC, rassoc wrote:
>> Recently I refactored some old code of mine, now utilizing 
>> classes instead structs, and I got hit by an uninitialized 
>> variable access pattern similar to the simplified example 
>> below.
>
> I think changing the structure will make things harder (I mean 
> in general). I know most people will object;  but classes are 
> useless.  Structs are enough for you for the rest of your life 😀
>
> SDB at 79

How would you do this without classes:

``` D
interface ForwardRange
{
   // ...
}

class Foo: ForwardRange
{
    // ...
}

class Bar: ForwardRange
{
   // ...
}

struct Baz
{
    ForwardRange r;

    this(ForwardRange r_)
    {
      r = r_;
    }
}
```


More information about the Digitalmars-d-learn mailing list