static class

2013-02-17 Thread Michael
Why members of static class are not implicitly static? static class Test { void foo() {} } Error: need 'this' for foo type void()

Static class question

2013-02-14 Thread Lubos Pintes
to ListBox: [code] private static class StringItem { private string _str; public this(string s) { this._str = s; } public override string toString

Re: static class

2013-02-17 Thread Andrej Mitrovic
On 2/17/13, Michael wrote: > Why members of static class are not implicitly static? > > static class Test > { > void foo() {} > } > That's not the meaning of static in that context. The above is useful in nested classes. Instead you can use: class Test { static: void foo() { } }

Re: static class

2013-02-17 Thread Michael
That's not the meaning of static in that context. As I understand a static class can't be instantiated. The above is useful in nested classes. I just read it. Holy s.. cow. Instead you can use: class Test { static: void foo() { } } So in mine case if I want purely stat

Re: static class

2013-02-17 Thread Steven Schveighoffer
On Sun, 17 Feb 2013 17:00:19 -0500, Michael wrote: That's not the meaning of static in that context. As I understand a static class can't be instantiated. Static in that position is a no-op. The compiler (infuriatingly sometimes) accepts attributes that have no meaning silen

Re: static class

2013-02-17 Thread Jonathan M Davis
On Sunday, February 17, 2013 23:00:19 Michael wrote: > > That's not the meaning of static in that context. > > As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. That's not what it means for a class to be static

Re: static class

2013-02-17 Thread H. S. Teoh
On Sun, Feb 17, 2013 at 11:46:24PM +0100, Andrej Mitrovic wrote: > On 2/17/13, Steven Schveighoffer wrote: > > A class that can't be instantiated has a private constructor. > > An alternative to that is: > > final abstract class C > { > static: > } > > You can't derive from it and you can't

Re: static class

2013-02-17 Thread Jonathan M Davis
On Sunday, February 17, 2013 14:47:12 H. S. Teoh wrote: > On Sun, Feb 17, 2013 at 11:46:24PM +0100, Andrej Mitrovic wrote: > > On 2/17/13, Steven Schveighoffer wrote: > > > A class that can't be instantiated has a private constructor. > > > > An alternative to that is: > > > > final abstract cla

Re: static class

2013-02-17 Thread Ben Davis
On 17/02/2013 22:25, Jonathan M Davis wrote: On Sunday, February 17, 2013 23:00:19 Michael wrote: That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. In fairness, it is the nat

Re: static class

2013-02-17 Thread Jonathan M Davis
On Sunday, February 17, 2013 23:26:37 Ben Davis wrote: > On 17/02/2013 22:25, Jonathan M Davis wrote: > > However, non-static nested classes are associated with an instance of the > > outer class, and therefore only one can exist per class instance. > > That's not true, is it? You can make as many

Re: static class

2013-02-17 Thread Steven Schveighoffer
On Sun, 17 Feb 2013 18:26:37 -0500, Ben Davis wrote: On 17/02/2013 22:25, Jonathan M Davis wrote: On Sunday, February 17, 2013 23:00:19 Michael wrote: That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how y

Re: static class

2013-02-18 Thread Maxim Fomin
On Sunday, 17 February 2013 at 22:26:16 UTC, Jonathan M Davis wrote: On Sunday, February 17, 2013 23:00:19 Michael wrote: > That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. Th

Re: static class

2013-02-18 Thread Ary Borenszweig
On 2/17/13 7:25 PM, Jonathan M Davis wrote: On Sunday, February 17, 2013 23:00:19 Michael wrote: That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. Probably because of t

Re: static class

2013-02-18 Thread dennis luehring
Am 17.02.2013 23:25, schrieb Jonathan M Davis: On Sunday, February 17, 2013 23:00:19 Michael wrote: > That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. That's not what it

Re: static class

2013-02-18 Thread Michael
Yes, it's comes from C#. So, there is no static for classes at module level. Good to have a msg for it at compile-time. import std.stdio; public final abstract class Test { static this() { writeln("in static ctor"); } static : void foo() { writeln("in static method"); } } void

Re: static class

2013-02-20 Thread Ben Davis
On 18/02/2013 21:25, Michael wrote: Yes, it's comes from C#. So, there is no static for classes at module level. Good to have a msg for it at compile-time. import std.stdio; public final abstract class Test { static this() { writeln("in static ctor"); } static : void foo() { writ

Re: static class

2013-02-21 Thread Michael
I'm sure you knew that and it's just a wording thing :) Fun fact: in Java, it's an error to combine 'final' and 'abstract'. Yes. As I understand, in D the "abstract" keyword is some alternative to @disable in that case.

Re: static class

2013-02-21 Thread Jonathan M Davis
On Thursday, February 21, 2013 19:52:39 Michael wrote: > > I'm sure you knew that and it's just a wording thing :) > > > > Fun fact: in Java, it's an error to combine 'final' and > > 'abstract'. > > Yes. > As I understand, in D the "abstract" keyword is some alternative > to @disable in that case

Re: static class

2013-02-21 Thread bearophile
Jonathan M Davis: D doesn't bother to check, so you get the natural consequence of mixing them. I'm quite sure that the fact that it works that way is an accident. It was never intentially made to be allowed or disallowed. It's just allowed, because there's nothing intrinsic about either of t

Re: static class

2013-02-21 Thread Jonathan M Davis
On Friday, February 22, 2013 00:06:26 bearophile wrote: > Jonathan M Davis: > > D doesn't > > bother to check, so you get the natural consequence of mixing > > them. I'm quite > > sure that the fact that it works that way is an accident. It > > was never > > intentially made to be allowed or disall

Re: static class

2013-02-21 Thread Ary Borenszweig
On 2/21/13 8:34 PM, Jonathan M Davis wrote: On Friday, February 22, 2013 00:06:26 bearophile wrote: Jonathan M Davis: D doesn't bother to check, so you get the natural consequence of mixing them. I'm quite sure that the fact that it works that way is an accident. It was never intentially made t

Re: static class

2013-02-21 Thread Jonathan M Davis
On Friday, February 22, 2013 00:59:45 Ary Borenszweig wrote: > On 2/21/13 8:34 PM, Jonathan M Davis wrote: > > On Friday, February 22, 2013 00:06:26 bearophile wrote: > >> Jonathan M Davis: > >>> D doesn't > >>> bother to check, so you get the natural consequence of mixing > >>> them. I'm quite > >

Re: static class

2013-02-22 Thread Andrej Mitrovic
On 2/22/13, Ary Borenszweig wrote: > Don't you see that as a problem? People loosing their time answering > this questions over and over again instead of the compiler giving you > the answer. They're losing their time if they expect D to act as another language. Anyway an annoying compiler compl

Re: static class

2013-02-22 Thread Michael
It's natural and would be good if something will be stated in documentation about static at top-level. "static" is well known feature. Yes it can act differently in diff languages. They're losing their time if they expect D to act as another language. With this point of view to user, only

Re: static class

2013-02-22 Thread Michael
On Friday, 22 February 2013 at 04:06:09 UTC, Jonathan M Davis wrote: I'm not talking about static. I'm talking about the fact that putting both final and abstract on a class isn't a problem. - Jonathan M Davis Initial question for me was how to get something like: They only contain static me

Re: static class

2013-02-22 Thread Jonathan M Davis
On Friday, February 22, 2013 20:39:01 Michael wrote: > On Friday, 22 February 2013 at 04:06:09 UTC, Jonathan M Davis > > wrote: > >I'm not talking about static. I'm talking about the fact that > >putting both final and abstract on a class isn't a problem. > > > > - Jonathan M Davis > > Initial qu

Re: static class

2013-02-22 Thread Michael
In D a module can be statically imported and then I can use full names. But question: is it possible to force a static import?

Re: static class

2013-02-22 Thread Jonathan M Davis
On Friday, February 22, 2013 22:12:44 Michael wrote: > In D a module can be statically imported and then I can use full > names. > > But question: is it possible to force a static import? No. - Jonathan M Davis

Local static class fields

2019-08-12 Thread Bert via Digitalmars-d-learn
Making a field static is effectively a global variable to the class. I have a recursive class structure(think of a graph or tree) and I need to keep a global state for it, but this state actually needs to be different for each tree object. The reason for this is that structurally it will not

Re: Static class question

2013-02-14 Thread anonymous
. For cases when string is added, he defined this small class, internal to ListBox: [code] private static class StringItem { private string _str; public this(string s) { this._str = s

Re: Local static class fields

2019-08-12 Thread DanielG via Digitalmars-d-learn
On Monday, 12 August 2019 at 22:48:43 UTC, Bert wrote: I have a recursive class structure(think of a graph or tree) and I need to keep a global state for it, If I'm understanding the problem correctly, it seems like you have a choice to make: either "bloat" the child nodes by the size of a po

Re: Local static class fields

2019-08-12 Thread Paul Backus via Digitalmars-d-learn
On Monday, 12 August 2019 at 22:48:43 UTC, Bert wrote: Making a field static is effectively a global variable to the class. I have a recursive class structure(think of a graph or tree) and I need to keep a global state for it, but this state actually needs to be different for each tree object

Re: Local static class fields

2019-08-13 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 04:43:29 UTC, Paul Backus wrote: On Monday, 12 August 2019 at 22:48:43 UTC, Bert wrote: Making a field static is effectively a global variable to the class. I have a recursive class structure(think of a graph or tree) and I need to keep a global state for it, but

Re: Local static class fields

2019-08-13 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 12 August 2019 at 22:48:43 UTC, Bert wrote: Making a field static is effectively a global variable to the class. I have a recursive class structure(think of a graph or tree) and I need to keep a global state for it, but this state actually needs to be different for each tree object

Re: Local static class fields

2019-08-13 Thread Bert via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 04:43:29 UTC, Paul Backus wrote: On Monday, 12 August 2019 at 22:48:43 UTC, Bert wrote: Making a field static is effectively a global variable to the class. I have a recursive class structure(think of a graph or tree) and I need to keep a global state for it, but

Re: Local static class fields

2019-08-13 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 08:41:02 UTC, Bert wrote: On Tuesday, 13 August 2019 at 04:43:29 UTC, Paul Backus wrote: It seems to me like the obvious solution is to use two different classes, one to store the global state, and one to store the individual objects in your structure. For example:

Re: Local static class fields

2019-08-14 Thread Bert via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 12:22:45 UTC, Simen Kjærås wrote: On Tuesday, 13 August 2019 at 08:41:02 UTC, Bert wrote: On Tuesday, 13 August 2019 at 04:43:29 UTC, Paul Backus wrote: It seems to me like the obvious solution is to use two different classes, one to store the global state, and one

Re: Local static class fields

2019-08-14 Thread Bert via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 00:17:13 UTC, DanielG wrote: On Monday, 12 August 2019 at 22:48:43 UTC, Bert wrote: I have a recursive class structure(think of a graph or tree) and I need to keep a global state for it, If I'm understanding the problem correctly, it seems like you have a choice

static class instances not allowed?

2013-06-11 Thread Eric
ass thread local variable are allowed, not T.Foo T.d(5): Error: variable T.g is mutable. Only const or immutable class thread local variable are allowed, not T.Foo Why aren't static class instances allowed? Is there a work-around, or alternative approach to this? Thanks, Eric

static class vs. static struct

2015-01-26 Thread ref2401 via Digitalmars-d-learn
What's the difference between static class and static struct? What should i use?

Re: static class vs. static struct

2015-11-19 Thread vyarthrot via Digitalmars-d-learn
On Monday, 26 January 2015 at 14:02:54 UTC, ref2401 wrote: What's the difference between static class and static struct? What should i use? In simple words, Singleton is a pattern and not a keyword. The Singleton pattern has several advantages over static classes. A singleton allows a

Re: static class instances not allowed?

2013-06-11 Thread bearophile
ble class thread local variable are allowed, not T.Foo T.d(5): Error: variable T.g is mutable. Only const or immutable class thread local variable are allowed, not T.Foo Why aren't static class instances allowed? Is there a work-around, or alternative approach to this? C# compilers pres

Re: static class instances not allowed?

2013-06-11 Thread Eric
Why aren't static class instances allowed? Is there a work-around, or alternative approach to this? C# compilers present bugs with a standard number, like: myprog.cs(7,60): error CS1525: ... This is useful because you can then write an explanation page for each of those bugs,

Re: static class instances not allowed?

2013-06-11 Thread Steven Schveighoffer
On Tue, 11 Jun 2013 10:04:21 -0400, Eric wrote: The following code does not compile: class Foo { int x; } class Bar { static Foo f = new Foo(); } // compiler error static Foo g = new Foo(); // compiler error These can be solved with a static ctor. Essentially, any static initializers mu

Re: static class instances not allowed?

2013-06-11 Thread Eric
On Tuesday, 11 June 2013 at 16:09:39 UTC, Steven Schveighoffer wrote: On Tue, 11 Jun 2013 10:04:21 -0400, Eric wrote: The following code does not compile: class Foo { int x; } class Bar { static Foo f = new Foo(); } // compiler error static Foo g = new Foo(); // compiler error These can

Re: static class instances not allowed?

2013-06-11 Thread bearophile
C# compilers present bugs with a standard number, like: myprog.cs(7,60): error CS1525: ... This is useful because you can then write an explanation page for each of those bugs, like CS1525: http://msdn.microsoft.com/en-gb/library/3hdyz4dw%28v=vs.80%29.aspx In such pages you can explain w

Static class members/methods and scope

2011-04-21 Thread Mike Parker
I'm certain this used to work: class Foo { public static { void bar() {} } } But I've found that now, anything inside the public static block is not actually static. I get an error attempting to call Foo.bar(). If I do this: class Foo { public { static void

Re: static class vs. static struct

2015-01-26 Thread bearophile via Digitalmars-d-learn
On Monday, 26 January 2015 at 14:02:54 UTC, ref2401 wrote: What's the difference between static class and static struct? What should i use? Non-static structs/classes have an extra pointer. Static ones don't have it, so their differences are the usual ones: a class is used by ref

Re: static class vs. static struct

2015-01-26 Thread Piotrek via Digitalmars-d-learn
On Monday, 26 January 2015 at 14:11:32 UTC, bearophile wrote: Non-static structs/classes have an extra pointer. Bye, bearophile Since when structs have an extra pointer? Maybe you are talking about nested structs? Piotrek

Re: static class vs. static struct

2015-01-26 Thread anonymous via Digitalmars-d-learn
On Monday, 26 January 2015 at 21:33:10 UTC, Piotrek wrote: On Monday, 26 January 2015 at 14:11:32 UTC, bearophile wrote: Non-static structs/classes have an extra pointer. Bye, bearophile Since when structs have an extra pointer? Maybe you are talking about nested structs? Non-static means

Re: static class vs. static struct

2015-01-27 Thread ref2401 via Digitalmars-d-learn
For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I've got a question. Why do Phobos guys use struct or static struct for or singleton pattern implementation? Why don't use sta

Re: static class vs. static struct

2015-01-27 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I've got a question. Why do Phobos guys use struct or static struc

Re: static class vs. static struct

2015-01-27 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 09:36:49 UTC, Daniel Kozak wrote: On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I

Re: static class vs. static struct

2015-01-27 Thread ketmar via Digitalmars-d-learn
On Tue, 27 Jan 2015 09:40:08 +, Daniel Kozak wrote: > import std.stdio; > import std.conv; > > struct S { > @disable this(); > } > > final class C { > } > > void main() { > writeln(C.sizeof); > writeln(S.sizeof); > } blind guess: vmt with "toString()" from Object? ;-) signa

Re: static class vs. static struct

2015-01-27 Thread Piotrek via Digitalmars-d-learn
On Monday, 26 January 2015 at 21:55:19 UTC, anonymous wrote: On Monday, 26 January 2015 at 21:33:10 UTC, Piotrek wrote: On Monday, 26 January 2015 at 14:11:32 UTC, bearophile wrote: Non-static structs/classes have an extra pointer. Bye, bearophile Since when structs have an extra pointer? Ma

Re: static class vs. static struct

2015-01-27 Thread Artur Skawina via Digitalmars-d-learn
On 01/27/15 10:40, Daniel Kozak via Digitalmars-d-learn wrote: > On Tuesday, 27 January 2015 at 09:36:49 UTC, Daniel Kozak wrote: >> On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: >>> For several times I've met struct(or static struct) usage in Phobos for >>> singleton pattern impleme

Re: static class vs. static struct

2015-01-27 Thread Piotrek via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 09:01:39 UTC, ref2401 wrote: For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I've got a question. Why do Phobos guys use struct or static struc

Re: static class vs. static struct

2015-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2015 08:58 AM, Piotrek wrote: Nice list. :) > 1. static variable > > struct A{int a} // no static before declaration > static A s; //note that static is used for struct variable storage class > (lifetime) > > static int b; > etc. > > 2. static declaration > > static struct A{int a}; //s

Re: static class vs. static struct

2015-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2015 08:33 AM, Piotrek wrote: >> Non-static means nested. > > Hmm,this can be misleading. Nesting in structs doesn't introduce context > pointer. You must be thinking of structs nested inside user-defined types. Structs that are nested inside functions do have the context pointer. Al

Re: static class vs. static struct

2015-01-27 Thread Piotrek via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 18:24:29 UTC, Ali Çehreli wrote: On 01/27/2015 08:33 AM, Piotrek wrote: >> Non-static means nested. > > Hmm,this can be misleading. Nesting in structs doesn't introduce context > pointer. You must be thinking of structs nested inside user-defined types. Structs t

Re: static class vs. static struct

2015-01-27 Thread Piotrek via Digitalmars-d-learn
On Tuesday, 27 January 2015 at 18:18:02 UTC, Ali Çehreli wrote: On 01/27/2015 08:58 AM, Piotrek wrote: Nice list. :) > 1. static variable > > struct A{int a} // no static before declaration > static A s; //note that static is used for struct variable storage class > (lifetime) > > static int b;

Re: static class vs. static struct

2015-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2015 01:44 PM, Piotrek wrote: > Let me here thank for your book I am glad that it is useful. > which I've been reading for some time. Me too! I browsed the index section to remember the other uses of 'static'. :) Ali

Re: static class vs. static struct

2015-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 01/27/2015 01:33 PM, Piotrek wrote: > On Tuesday, 27 January 2015 at 18:24:29 UTC, Ali Çehreli wrote: >> On 01/27/2015 08:33 AM, Piotrek wrote: >> >> >> Non-static means nested. >> > >> > Hmm,this can be misleading. Nesting in structs doesn't >> introduce context >> > pointer. Oh, I misread w

Re: static class vs. static struct

2015-07-15 Thread creiglee via Digitalmars-d-learn
instance (reference to that instance) can be passed as a parameter to other methods, and treated as a normal object. While a static class allows only static methods and and you cannot pass static class as parameter. More about. http://net-informations.com/faq/netfaq/singlestatic.htm Lee

What's the secret to static class members

2016-06-29 Thread Guido via Digitalmars-d-learn
I'm using a static class member in a parent class, but can't get the compiler to see it. Class Grid{ public: uint xdim; } Class Holder : Grid { uint var; } Any of the following should work, but none of them do: Grid.xdim = 0; grid = new Grid; grid.xdim = 0; holder =

Re: Static class members/methods and scope

2011-04-21 Thread Steven Schveighoffer
On Thu, 21 Apr 2011 04:54:49 -0400, Mike Parker wrote: I'm certain this used to work: class Foo { public static { void bar() {} } } But I've found that now, anything inside the public static block is not actually static. I get an error attempting to call Foo.bar(). I

Re: What's the secret to static class members

2016-06-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 15:18:53 UTC, Guido wrote: I'm using a static class member in a parent class, but can't get the compiler to see it. Class Grid{ public: uint xdim; } That's not static do `static uint xdim;` if you want it static (in this context, sta

Re: What's the secret to static class members

2016-06-29 Thread Guido via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 15:18:53 UTC, Guido wrote: I'm using a static class member in a parent class, but can't get the compiler to see it. Class Grid{ public: uint xdim; } Class Holder : Grid { uint var; } Any of the following should work, but none of them do: Gri

Re: What's the secret to static class members

2016-06-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 15:33:58 UTC, Guido wrote: The problem is actually much more profound. The classes need to be declared outside the main() scope. WTF?!?!?! Not true. What are you actually trying to compile?

Re: What's the secret to static class members

2016-06-29 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 15:33:58 UTC, Guido wrote: The problem is actually much more profound. The classes need to be declared outside the main() scope. WTF?!?!?! I put them in main() so they would be in scope. This seems like a *MAJOR* design flaw with the language, not to mention the

Re: What's the secret to static class members

2016-06-29 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 15:33:58 UTC, Guido wrote: The problem is actually much more profound. The classes need to be declared outside the main() scope. WTF?!?!?! It's not going to work anywhere if you type 'Class' as opposed to 'class'. Types can be declared in any scope: ``` void ma

Re: What's the secret to static class members

2016-06-29 Thread Guido via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 15:40:57 UTC, Andrea Fontana wrote: On Wednesday, 29 June 2016 at 15:33:58 UTC, Guido wrote: The problem is actually much more profound. The classes need to be declared outside the main() scope. WTF?!?!?! I put them in main() so they would be in scope. This seems

Re: What's the secret to static class members

2016-06-29 Thread ag0aep6g via Digitalmars-d-learn
On 06/29/2016 07:00 PM, Guido wrote: On another topic, tuples seem to have a major problem as well. Tuple!(float, float, float) test; Tuple!(float, float, float) [] array_data; test[0] = 1.0; // works array_data[i][0] = 1.0; // doesn't work. Works just fine for me, if I add the missing piece

Re: What's the secret to static class members

2016-06-29 Thread Lodovico Giaretta via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 17:00:49 UTC, Guido wrote: I have all this business generally working in C++. I just wanted to try D for a production level quick project. So, the language is not ready. I'm really sad about this. I had hoped that I could get some useful work done. C++ is painfully

Re: What's the secret to static class members

2016-06-29 Thread FreeSlave via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 17:00:49 UTC, Guido wrote: Tuple!(float, float, float) test; Tuple!(float, float, float) [] array_data; test[0] = 1.0; // works array_data[i][0] = 1.0; // doesn't work. Compile-time error, probably because the language itself doesn't have a dedicated It works

Re: What's the secret to static class members

2016-06-29 Thread Ali Çehreli via Digitalmars-d-learn
On 06/29/2016 10:00 AM, Guido wrote: > doesn't work. As others said, everything that you've mentioned do indeed work: void main() { class Grid { public: static uint xdim; } class Holder : Grid { uint var; } Grid.xdim = 0; auto grid = new Grid;

Re: What's the secret to static class members

2016-06-29 Thread chmike via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 17:00:49 UTC, Guido wrote: On Wednesday, 29 June 2016 at 15:40:57 UTC, Andrea Fontana wrote: On Wednesday, 29 June 2016 at 15:33:58 UTC, Guido wrote: The problem is actually much more profound. The classes need to be declared outside the main() scope. WTF?!?!?! I

Re: What's the secret to static class members

2016-06-29 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 29 June 2016 at 19:10:18 UTC, chmike wrote: Claiming the problems you encountered are due to bad design of the language is unfair if you don't expose clearly the problem and verify the problem is not your side. There is a deeply thought rationale for every rule of the D languag

Re: What's the secret to static class members

2016-06-30 Thread Dejan Lekic via Digitalmars-d-learn
On Thursday, 30 June 2016 at 01:11:09 UTC, Mike Parker wrote: I think it's safe to say this guy is just trolling and we can ignore him. I was about to say the same, Mike. He is either trolling, or genuinely did not even bother to learn some language basics...

d equivilent of java's public static class fields

2010-08-08 Thread %u
I'm porting some code from Java to D and am getting stuck on what Java calls static class fields. I can't find out how to write the functional (or best practices) equivalent in D. (There are other syntax errors in D code, I'm fixing them one by one) # Begin D code (ported

Re: d equivilent of java's public static class fields

2010-08-08 Thread Simen kjaeraas
%u wrote: I'm porting some code from Java to D and am getting stuck on what Java calls static class fields. I can't find out how to write the functional (or best practices) equivalent in D. [snip] static int CORRECT = 0; [snip] int asd = Answer.CORRECT; <-- compile erro

Re: d equivilent of java's public static class fields

2010-08-08 Thread bearophile
Simen kjaeraas: > class Answer { > alias int Correctness; > enum Correctness CORRECT = 0; > enum Correctness WRONG = 1; > > Correctness _answerCode; > string _answerText; > > @property Correctness answerCode( ) const { > return _answerCode; > } 'Correc

Re: d equivilent of java's public static class fields

2010-08-08 Thread Simen kjaeraas
bearophile wrote: Simen kjaeraas: class Answer { alias int Correctness; enum Correctness CORRECT = 0; enum Correctness WRONG = 1; Correctness _answerCode; string _answerText; @property Correctness answerCode( ) const { return _answerCode; } 'Corr

Re: d equivilent of java's public static class fields

2010-08-08 Thread Lutger
bearophile wrote: > Simen kjaeraas: >> class Answer { >> alias int Correctness; >> enum Correctness CORRECT = 0; >> enum Correctness WRONG = 1; >> >> Correctness _answerCode; >> string _answerText; >> >> @property Correctness answerCode( ) const { >> return

Re: d equivilent of java's public static class fields

2010-08-09 Thread Jacob Carlborg
On 2010-08-08 21:12, %u wrote: I'm porting some code from Java to D and am getting stuck on what Java calls static class fields. I can't find out how to write the functional (or best practices) equivalent in D. (There are other syntax errors in D code, I'm fixing

Re: d equivilent of java's public static class fields

2010-08-09 Thread Jacob Carlborg
On 2010-08-08 21:28, Simen kjaeraas wrote: %u wrote: I'm porting some code from Java to D and am getting stuck on what Java calls static class fields. I can't find out how to write the functional (or best practices) equivalent in D. [snip] static int CORRECT = 0; [snip

Re: d equivilent of java's public static class fields

2010-08-09 Thread Simen kjaeraas
Jacob Carlborg wrote: Since when is the default access level in D private? Uhm, since I made it up? Sorry about that, I believe I mixed it up with C++. -- Simen

Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread thebluepandabear via Digitalmars-d-learn
Hi, In Java/C# you can create purely static classes. These are classes whose methods are all static, the classes cannot be derived from or instantiated: ``` static class Algo { void drawLine(Canvas c, Pos from, Pos to) { .. }; } ``` Class in use: ``` Algo.drawLine(new Canvas(), new

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear wrote: Hi, In Java/C# you can create purely static classes. These are classes whose methods are all static, the classes cannot be derived from or instantiated: ``` static class Algo { void drawLine(Canvas c, Pos from, Pos to

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
class can be instantiated. However, unlike in Java and C#, you cannot call a function without instantiating said class, as functions act on the class object. Also, there is a `static` keyword, but a `static class` can be instantiated as a member of the external class.

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread thebluepandabear via Digitalmars-d-learn
ll a function without instantiating said class, as functions act on the class object. Ok, thanks. I think D should implement something similar to `static class` but I doubt it will happen.

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 13:03:18 UTC, thebluepandabear wrote: ll a function without instantiating said class, as functions act on the class object. Ok, thanks. I think D should implement something similar to `static class` but I doubt it will happen. D isn't Java, and never wi

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread evilrat via Digitalmars-d-learn
On Friday, 20 January 2023 at 13:17:05 UTC, Ruby The Roobster wrote: On Friday, 20 January 2023 at 13:03:18 UTC, thebluepandabear wrote: ll a function without instantiating said class, as functions act on the class object. Ok, thanks. I think D should implement something similar to `static

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Hipreme via Digitalmars-d-learn
On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear wrote: Hi, In Java/C# you can create purely static classes. These are classes whose methods are all static, the classes cannot be derived from or instantiated: ``` static class Algo { void drawLine(Canvas c, Pos from, Pos to

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 13:38:47 UTC, evilrat wrote: On Friday, 20 January 2023 at 13:17:05 UTC, Ruby The Roobster ... [snip] Also there is various import options such as renamed import or static import(doesn't add module to a scope thus requiring to fully qualify it) static import, c

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 20 January 2023 at 13:38:52 UTC, Hipreme wrote: On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear wrote: ... [snip] With a single file, you can do: ```d final class Algo { @disable this(); static: void drawLine(...){} } ``` This also works, but it dissimilar

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/20/23 6:28 AM, thebluepandabear wrote: This type of semantics is not possible in D, which sucks. Well, static methods do exactly this. If you want to disable class creation, then use `@disable this();`, if you want to make all methods static, put `static:` at the top of the class. Not

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread torhu via Digitalmars-d-learn
On Friday, 20 January 2023 at 11:28:23 UTC, thebluepandabear wrote: Hi, In Java/C# you can create purely static classes. These are classes whose methods are all static, the classes cannot be derived from or instantiated: ``` static class Algo { void drawLine(Canvas c, Pos from, Pos to

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ali Çehreli via Digitalmars-d-learn
On 1/20/23 07:01, torhu wrote: > But why not have drawLine just be a free function? Exactly. If I'm not mistaken, and please teach me if I am wrong, they are practically free functions in Java as well. That Java class is working as a namespace. So, the function above is the same as the follow

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 20, 2023 at 01:32:22PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 1/20/23 07:01, torhu wrote: > > > But why not have drawLine just be a free function? > > Exactly. > > If I'm not mistaken, and please teach me if I am wrong, they are > practically free functions in Java a

  1   2   3   >