C++ Logo

sg12

Advanced search

Re: [SG12] [isocpp-lib-ext] (draft) The simple truth about references

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Fri, 7 Feb 2020 09:28:54 +0200
On Fri, 7 Feb 2020 at 09:05, Herb Sutter via Lib-Ext
<lib-ext_at_[hidden]> wrote:
> Aren't local references useful to express aliases, for example to a member of an array or container?
>
> Yes. Pointers can do it equivalently, it's a style choice.
>
> For example, this local reference is useful:
>
> int& r = a[f(i)];
>
> // ... then use r repeatedly ...
>
> Or you can equivalently use a pointer:
>
> int* p = a[f(i)];
>
> // ... then use *p repeatedly ...

Is that latter line intended to be
int* p = &a[f(i)];
?

Received on 2020-02-07 01:31:43