Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 09, 2011 Re: How do I create a module-local immutable class object? | ||||
---|---|---|---|---|
| ||||
Ok it seems using const works, so I can use that instead. Still I'm wondering why I can't initialize foo inside a module ctor. |
September 09, 2011 Re: How do I create a module-local immutable class object? | ||||
---|---|---|---|---|
| ||||
Wait a minute, I've just realized private on a class definition has no effect. Why is that? |
September 09, 2011 Re: How do I create a module-local immutable class object? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 09/09/2011 11:36 PM, Andrej Mitrovic wrote:
> Ok it seems using const works, so I can use that instead. Still I'm
> wondering why I can't initialize foo inside a module ctor.
It works for const because mutable is implicitly convertible to const, but not to immutable. You have to allocate an immutable class instance to make it work.
foo = new immutable(Foo);
|
September 10, 2011 Re: How do I create a module-local immutable class object? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | Andrej Mitrovic Wrote:
> Wait a minute, I've just realized private on a class definition has no effect. Why is that?
Try to import that class from another module...
Bye,
bearophile
|
September 10, 2011 Re: How do I create a module-local immutable class object? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | > Try to import that class from another module...
I fear this is a D design mistake/corner case. If you add tags to a class/struct definition it usually gets applied to all its methods, but here it works on the class/struct name itself.
Bye,
bearophile
|
September 10, 2011 Re: How do I create a module-local immutable class object? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Saturday, September 10, 2011 05:20:51 bearophile wrote:
> > Try to import that class from another module...
>
> I fear this is a D design mistake/corner case. If you add tags to a class/struct definition it usually gets applied to all its methods, but here it works on the class/struct name itself.
Personally, I think that marking a class with an attribute should only apply to the class and _nothing_ in it, but it doesn't always seem to work that way.
- Jonathan M Davis
|
September 10, 2011 Re: How do I create a module-local immutable class object? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 9/10/11, bearophile <bearophileHUGS@lycos.com> wrote:
> Andrej Mitrovic Wrote:
>
>> Wait a minute, I've just realized private on a class definition has no effect. Why is that?
>
> Try to import that class from another module...
It doesn't stop imports, that's what I'm saying. I can import and instantiate the class from another module even though it's a private class definition.
|
September 10, 2011 Re: How do I create a module-local immutable class object? | ||||
---|---|---|---|---|
| ||||
On 9/10/11, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
> Personally, I think that marking a class with an attribute should only apply to the class and _nothing_ in it.
Agreed. But this doesn't seem to work currently unless I'm doing something wrong..
|
September 10, 2011 Re: How do I create a module-local immutable class object? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | Andrej Mitrovic:
> It doesn't stop imports, that's what I'm saying. I can import and instantiate the class from another module even though it's a private class definition.
I didn't know it. If it's all like you say, then it's a bug.
Bye,
bearophile
|
September 10, 2011 Re: How do I create a module-local immutable class object? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | foo\bar.d: module foo.bar; private class Foo {} main.d: import foo.bar : Foo; void main() { auto foo = new Foo(); } This should be a compile error, no? |
Copyright © 1999-2021 by the D Language Foundation