Returning references to const data from const methods
Jarrett Billingsley
kb3ctd2 at yahoo.com
Tue Jun 19 04:59:20 PDT 2007
"Leonard Dahlmann" <leo.dahlmann at gmail.com> wrote in message
news:f57tbr$p41$1 at digitalmars.com...
> How could I do the following?
>
> I'm getting this error message:
> test.d(15): Error: c.gimme can only be called on a mutable object
>
> <code>
> class Foo
> {
> uint x;
>
> const (const(uint)*) gimme()
> {
> return &x;
> }
> }
>
> void main()
> {
> const(Foo) c = new Foo;
>
> const(uint)* x = c.gimme(); // line 15
> }
> </code>
Don't have the D2 compiler here, but shouldn't that be
invariant const(uint)* gimme()
?
More information about the Digitalmars-d-learn
mailing list