Why can't we make reference variables?
anonymous
anonymous at example.com
Tue Aug 28 19:40:17 PDT 2012
On Wednesday, 29 August 2012 at 02:07:19 UTC, Nick Sabalausky
wrote:
> On Wed, 29 Aug 2012 03:16:20 +0200
> "Tommi" <tommitissari at hotmail.com> wrote:
>
>> On Wednesday, 29 August 2012 at 00:34:02 UTC, cal wrote:
>> > On Wednesday, 29 August 2012 at 00:21:29 UTC, Tommi wrote:
>> >> In this situation, I think, the most convenient and
>> >> sensible thing to do is to make a reference to the data,
>> >> and use that reference multiple times. We could make a
>> >> pointer, but then we'd be stuck with the nasty syntax of
>> >> dereferencing:
>> >
>> > This works currently:
>> >
>> > struct Test
>> > {
>> > void foo() const
>> > {
>> > writeln("FOO");
>> > }
>> > }
>> >
>> > void main()
>> > {
>> > immutable(Test)* ptr = new immutable(Test);
>> > ptr.foo();
>> > }
>>
>> Now, that's a surprise for someone coming from C++. But even
>> though ptr looks like a reference variable in your example, it
>> doesn't look like it at all in this example:
>>
>
> I've been primarily a D guy for years, and even I'm surprised
> by that!
> O_O
You didn't know that the dot operator does dereference? That's
quite a big one to miss for years.
More information about the Digitalmars-d
mailing list