Returning references to const data from const methods

Christian Kamm kamm.incasoftware at shift-at-left-and-remove-this.de
Tue Jun 19 05:22:13 PDT 2007


> How could I do the following?
> 
> <code>
> class Foo
> {
> uint x;
> 
> const (const(uint)*) gimme()
> {
> return &x;
> }
> }

I think you have to remove the outermost parentheses. Probably the compiler
thinks the return type is const(const(uint)*) for a normal method and not
const(uint)* for a const method.

This works for me:

alias const(uint)* returnType;
const returnType gimme() {...}

But this fails to compile:

const const(uint)* gimme() {...}

Cheers,
Christian


More information about the Digitalmars-d-learn mailing list