Thread overview
functions cannot be const or auto
Dec 13, 2007
popka
Dec 13, 2007
Janice Caron
Dec 14, 2007
popka
Dec 14, 2007
Pedro Ferreira
Dec 13, 2007
Janice Caron
December 13, 2007
Hi all,

I'm new to D and I've encountered an error message which is confusing me. I am trying to write a 'const' member function, i.e. one which does not modify the object.

If I understand correctly, the D syntax for this is:

class Foo {
  const void f() {}
}

However, this gives me the following error:

test.d(2): function test.Foo.f functions cannot be const or auto

I have tried this using both DMD and GDC. What am I doing wrong?

Many thanks.
December 13, 2007
"popka" <popka@dodgit.com> wrote in message news:fjrshb$1j2j$1@digitalmars.com...
> Hi all,
>
> I'm new to D and I've encountered an error message which is confusing me. I am trying to write a 'const' member function, i.e. one which does not modify the object.
>
> If I understand correctly, the D syntax for this is:
>
> class Foo {
>  const void f() {}
> }
>
> However, this gives me the following error:
>
> test.d(2): function test.Foo.f functions cannot be const or auto
>
> I have tried this using both DMD and GDC. What am I doing wrong?

You're using the D1 compiler, not the D2 compiler.  Only D2 has constness.

As far as I know there is no D2-compatible GDC, only DMD.


December 13, 2007
On 12/13/07, popka <popka@dodgit.com> wrote:
> test.d(2): function test.Foo.f functions cannot be const or auto
>
> I have tried this using both DMD and GDC. What am I doing wrong?

If I had to guess, I'd say you're probably using D version 1, wheras const proper is only available in D version 2.
December 13, 2007
On 12/13/07, Jarrett Billingsley <kb3ctd2@yahoo.com> wrote:
> Only D2 has constness.

D1 still has the "const" keyword, which I'm sure is what's confusing popka. In D1, the const keyword is used for invariant data. (I'm not making this up! :-) ) I guess Walter was thinking ahead.

Anyway, I'm sure that the real problem here is - as /many/ people have pointed out - the default documentation is for D2, but the default download is D1. That's gotta confuse /any/ visitor. (It confused me!)
December 14, 2007
Janice Caron Wrote:

> On 12/13/07, Jarrett Billingsley <kb3ctd2@yahoo.com> wrote:
> > Only D2 has constness.
> 
> D1 still has the "const" keyword, which I'm sure is what's confusing popka. In D1, the const keyword is used for invariant data. (I'm not making this up! :-) ) I guess Walter was thinking ahead.
> 
> Anyway, I'm sure that the real problem here is - as /many/ people have pointed out - the default documentation is for D2, but the default download is D1. That's gotta confuse /any/ visitor. (It confused me!)

Thanks, both of you. I'll continue using version 1 without this feature as it seems Derelict does not support 2.0.
December 14, 2007
popka Wrote:

> Janice Caron Wrote:
> 
> > On 12/13/07, Jarrett Billingsley <kb3ctd2@yahoo.com> wrote:
> > > Only D2 has constness.
> > 
> > D1 still has the "const" keyword, which I'm sure is what's confusing popka. In D1, the const keyword is used for invariant data. (I'm not making this up! :-) ) I guess Walter was thinking ahead.
> > 
> > Anyway, I'm sure that the real problem here is - as /many/ people have pointed out - the default documentation is for D2, but the default download is D1. That's gotta confuse /any/ visitor. (It confused me!)
> 
> Thanks, both of you. I'll continue using version 1 without this feature as it seems Derelict does not support 2.0.

Wrong. Check the forums, someone has already ported Derelict to DMD 2.