this() const

sclytrack sclytrack at ars.com
Sun Apr 22 13:31:57 PDT 2012


On 04/16/2012 09:27 PM, sclytrack wrote:
> On 04/16/2012 08:15 PM, sclytrack wrote:
>>
>>> const numbers = new int[2];
>>> const c = const(AB)(a, 20, numbers);
>>> writeln(c);
>>> }
>>>
>>> Bye,
>>> bearophile
>>
>> That's exactly what I needed, thanks.
>
> Seems to be forwarded to the constructor if there is one.
>
>
> (untested code)
>
> struct B
> {
> int [] _list;
>
> this( const int [] list) const
> {
> _list = list;
> //typeof(_list)=int []
> //typeof(list) =const(int[])
>
> }
> }
>
>
>
> Because of the const on the back of the constructor.
> Normally the typeof(_list) should be const(int[])
> but assignable once, because we are in the constructor.
>




this() const
{
	_a = 10;
	_a++;		//This is wrong. ??
}

with _a a private variable. The _a++ is going to be incorrect in the 
future right?





Below is me talking nonsense ignore it.
>
> But a mutable design has been chosen (_list is int [])
> until it is baked or cooked
> or whatever the terminology. (don't have Andrei's book)
> Probably for flexibility. Are there people out there
> using this flexibility?
>
> Just pondering,
>
> Sclytrack



More information about the Digitalmars-d-learn mailing list