Why members of static class are not implicitly static?
static class Test
{
void foo() {}
}
Error: need 'this' for foo type void()
to
ListBox:
[code]
private static class StringItem
{
private string _str;
public this(string s)
{
this._str = s;
}
public override string toString
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() { }
}
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
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
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
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
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
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
> >
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
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
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
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
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?
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
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
.
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
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
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
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
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
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
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:
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
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
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
What's the difference between static class and static struct?
What should i use?
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
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
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,
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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;
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
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
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
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 =
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
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
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
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?
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
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
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
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
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
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
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;
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
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
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...
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
%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
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
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
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
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
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
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
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
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
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.
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.
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
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
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
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
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
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
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
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
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 - 100 of 282 matches
Mail list logo