readonly?

Artur Skawina art.08.09 at gmail.com
Wed Jul 11 03:05:24 PDT 2012


On 07/11/12 11:49, David Nadlinger wrote:
> On Wednesday, 11 July 2012 at 08:56:39 UTC, Artur Skawina wrote:
>> On 07/11/12 09:00, Tobias Pankrath wrote:
>>> Bar b = new Bar;
>>> auto b2 = &b; // type of b2 is Bar*
>>>
>>> So does it meen, that a pointer of type Bar* does not point to the real object?
>>
>> Yeah, unfortunately.
>> Can anybody think of a reason to keep the current (broken) behavior?
> 
> Why would it be broken? Bar intrinsically is a reference type, so Bar* is a pointer to a reference.

Because it doesn't let you have a real pointer to a class.

The obvious alternative would be:

   auto r = new Bar(); // reference
   Bar* p = r;         // pointer to Bar; ref implicitly converts to pointer.
   auto pr = &r;       // typeof(pr)==Bar** ; can't do better w/o ref types.

So, does the current scheme have any advantages?
(currently, the second example is illegal and the last '&r' expression results
 in 'Bar *')

artur


More information about the Digitalmars-d-learn mailing list