New With Struct and Getting Class Object Pointers

Vijay Nayar madric at gmail.com
Wed Oct 3 07:05:19 UTC 2018


On Sunday, 30 September 2018 at 11:11:09 UTC, Nicholas Wilson 
wrote:
> On Sunday, 30 September 2018 at 09:30:38 UTC, Vijay Nayar wrote:
>> Is there a way to either have a constant reference to a class 
>> that can be set to a new value, or is there a way to convert 
>> the class variable to a class pointer?
>
> Alex has mentioned Rebindable, which is the answer to your 
> first question.
> To answer your second question, no
>
> class A {}
>
> A a:
>
> `a` is always a (possibly null) reference to a class instance. 
> You can have pointers to class references (which is what `&a` 
> gives you) but that has two indirections between the variable 
> and the data, which if you want high perf is probably not what 
> you are looking for.

Thanks everyone for the insight.  I also finished reading 
Jonathan's article: 
http://jmdavisprog.com/articles/why-const-sucks.html

I've run into just about every single problem described there, 
but had no idea just how deep the problem goes.  So it was a 
depressing read, but I'm glad to have the deeper understanding.  
I'm definitely more open now to see what "__mutable" could offer 
as was discussed at DConf2018, though I'm curious about how it 
would remain compatible with "immutable".


More information about the Digitalmars-d-learn mailing list