Express "Class argument may not be null" ?

Johan Engelen via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 8 12:59:45 PDT 2017


On Tuesday, 8 August 2017 at 19:38:19 UTC, Steven Schveighoffer 
wrote:
>
> Note that C++ also can do this, so I'm not sure the & is 
> accomplishing the correct goal:
>
> void foo(Klass&);
>
> int main()
> {
>    Klass *k = NULL;
>    foo(*k);
> }

In C++, it is clear that the _caller_ is doing the dereferencing, 
and the dereference is also explicit.

> However, the in contract does actually enforce the requirement.

And adds null pointer checks even when clearly not needed.

- Johan





More information about the Digitalmars-d-learn mailing list