| Thread overview | ||||||||
|---|---|---|---|---|---|---|---|---|
|
December 13, 2007 functions cannot be const or auto | ||||
|---|---|---|---|---|
| ||||
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 Re: functions cannot be const or auto | ||||
|---|---|---|---|---|
| ||||
Posted in reply to popka | "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 Re: functions cannot be const or auto | ||||
|---|---|---|---|---|
| ||||
Posted in reply to popka | 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 Re: functions cannot be const or auto | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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 Re: functions cannot be const or auto | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Janice Caron | 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 Re: functions cannot be const or auto | ||||
|---|---|---|---|---|
| ||||
Posted in reply to popka | 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.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply