Passing Structs to function like in C

D.Rex via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 14 09:21:58 PDT 2016


On Sunday, 14 August 2016 at 14:59:17 UTC, Adam D. Ruppe wrote:
> On Sunday, 14 August 2016 at 14:54:27 UTC, D.Rex wrote:
>> Speaking of classes, and this may have been answered 
>> elsewhere, but I am yet to find said answer, or am just 
>> missing something right in front of my face...but how does one 
>> go about accessing a method from a class if said class is 
>> passed to a function as a pointer?
>
> It just works with the regular dot.
>
> But don't pass classes as pointers in D except in very rare 
> circumstances. They are already pointers under the hood 
> automatically.

So you can access a method from a class pointer the same way you 
would access a method from a class normally?

so '&foo.bar();' works the same as 'foo.bar();'?

ah that makes sense, classes being pointers behind the scenes, 
Most of my programming experience is in Java, so the usage of 
pointers is a rather new concept for me.

Thank you kindly for your answer, much appreciated!! :-)


More information about the Digitalmars-d-learn mailing list