Passing Structs to function like in C

Cauterite via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 14 13:46:55 PDT 2016


On Sunday, 14 August 2016 at 16:21:58 UTC, D.Rex wrote:
> so '&foo.bar();' works the same as 'foo.bar();'?

with pointers, D automatically rewrites expressions like this:
	f.fooMethod()
to this:
	(*f).fooMethod()
which is why you're able to index an object-pointer-pointer 
(Foo*) the same way as an object-pointer (Foo).

Most built-in D types have value semantics, so it's 
understandable that you wouldn't expect classes to be reference 
types.

Associative arrays are also reference types, FYI.

Structs on the other hand are value types; if you're new to the 
language make sure you familiarise yourself with the differences 
between structs and classes.


More information about the Digitalmars-d-learn mailing list