Express "Class argument may not be null" ?
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 9 05:47:49 PDT 2017
On 8/8/17 3:59 PM, Johan Engelen wrote:
> 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.
In fact it's not doing any dereferencing. It's just under the hood
passing a pointer.
>> However, the in contract does actually enforce the requirement.
>
> And adds null pointer checks even when clearly not needed.
Clearly not needed? I thought the point was to ensure the reference is
not null?
-Steve
More information about the Digitalmars-d-learn
mailing list