Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
April 03, 2008 const/invariant bug? | ||||
---|---|---|---|---|
| ||||
Unless I misunderstand something this shouldn't compile. But it compiles fine in DMD 2.012. Is this a bug? import std.stdio; class A { public: int x = 0; void setX(int nx) const { x = nx; } } void foo(const A a) { a.setX(1); } int main(char[][] args) { A a = new A; foo(a); writefln(a.x); return 0; } |
April 03, 2008 Re: const/invariant bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Craig Black | You're right, it shouldn't compile. |
April 03, 2008 Re: const/invariant bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Craig Black | Craig Black wrote:
> void setX(int nx) const { x = nx; }
That should work, but at the moment:
const void setX(int nx) { x = nx; }
does work.
|
April 03, 2008 Re: const/invariant bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright schrieb:
> Craig Black wrote:
>> void setX(int nx) const { x = nx; }
>
> That should work, but at the moment:
>
> const void setX(int nx) { x = nx; }
>
> does work.
Why do we need the suffix "const" anyway ? Isnt unambiguity a virtue ?
|
April 03, 2008 Re: const/invariant bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Extrawurst | Extrawurst wrote:
> Why do we need the suffix "const" anyway ? Isnt unambiguity a virtue ?
Some people prefer it.
|
April 03, 2008 Re: const/invariant bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright schrieb:
> Extrawurst wrote:
>> Why do we need the suffix "const" anyway ? Isnt unambiguity a virtue ?
>
> Some people prefer it.
Some people seem to prefer untransitive const too ;)
(i am not one of those, to pe clear on that)
|
April 03, 2008 Re: const/invariant bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Thu, 03 Apr 2008 11:33:10 -0700, Walter Bright wrote: > Extrawurst wrote: >> Why do we need the suffix "const" anyway ? Isnt unambiguity a virtue ? > > Some people prefer it. Does that principal also apply to 'alias' or 'maifest' or 'define' instead of enum for manifest constants? -- Derek Parnell Melbourne, Australia skype: derek.j.parnell |
April 05, 2008 Re: const/invariant bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | "Walter Bright" <newshound1@digitalmars.com> wrote in message news:ft380r$13vn$1@digitalmars.com... > Extrawurst wrote: >> Why do we need the suffix "const" anyway ? Isnt unambiguity a virtue ? > > Some people prefer it. > const void setX(int nx) { x = nx; } Since there has, understandably, been some confusion about what const refers to with the prefixed form, why don't we get rid of the prefixed form altogether for 2.0? You could still allow: class C { const { int[] foo() { } // int[] foo() const { } double[] bar() { } // double[] bar() const { } } } because you have to do const(int[]) foo() to specify it for the return type anyhow, which is consistent between member and non-member functions. I doubt at this point it would break all that much code and the deprecated switch could serve in the interim. I really think this change would be worth it considering all of the confusion the prefix form will cause down the road, especially for C++ users. Thanks, - Dave |
Copyright © 1999-2021 by the D Language Foundation