www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to call one static method from another?

reply Konstantin Kutsevalov <adamasantares gmail.com> writes:
Hi,

Just can't found information about "this" for static methods.
Can anyone explain how to call current class from static methods?

For example I have some class and I need to call some static 
method of current class from another static method. I don't like 
to use full class name for that, but I didn't know what need to 
use instead of "this".

I sure it must be something like "self". :(
Jun 13 2016
parent reply Konstantin Kutsevalov <adamasantares gmail.com> writes:
May be my question was not enought clean...
this is example of code:

```
class ClassName {

     public static void function method1()
     {
         // do something
         // and now I need to call other static method
         ClassName.method2(); // What I can use insted of full 
class name?
         // Like "self.method2()"
     }

     public static void function method2()
     {
         //...
     }
}
```
Jun 14 2016
parent reply Andrea Fontana <nospam example.com> writes:
On Tuesday, 14 June 2016 at 07:20:47 UTC, Konstantin Kutsevalov 
wrote:
 May be my question was not enought clean...
 this is example of code:

 ```
 class ClassName {

     public static void function method1()
     {
         // do something
         // and now I need to call other static method
         ClassName.method2(); // What I can use insted of full 
 class name?
         // Like "self.method2()"
     }

     public static void function method2()
     {
         //...
     }
 }
 ```
Simply: method2(); Anyway I guess you mean public static void method1() { } without "function" Andrea
Jun 14 2016
next sibling parent Konstantin Kutsevalov <adamasantares gmail.com> writes:
On Tuesday, 14 June 2016 at 07:35:36 UTC, Andrea Fontana wrote:
 On Tuesday, 14 June 2016 at 07:20:47 UTC, Konstantin Kutsevalov 
 wrote:
 May be my question was not enought clean...
 this is example of code:

 ```
 class ClassName {

     public static void function method1()
     {
         // do something
         // and now I need to call other static method
         ClassName.method2(); // What I can use insted of full 
 class name?
         // Like "self.method2()"
     }

     public static void function method2()
     {
         //...
     }
 }
 ```
Simply: method2(); Anyway I guess you mean public static void method1() { } without "function" Andrea
Yep, it's my mistake about "function" :) Thanks!
Jun 14 2016
prev sibling parent reply pineapple <meapineapple gmail.com> writes:
On Tuesday, 14 June 2016 at 07:35:36 UTC, Andrea Fontana wrote:
 Simply:
 method2();
Also, typeof(this).method2();
Jun 14 2016
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 6/14/16 6:08 AM, pineapple wrote:
 On Tuesday, 14 June 2016 at 07:35:36 UTC, Andrea Fontana wrote:
 Simply:
 method2();
Also, typeof(this).method2();
Yes, if you want to distinguish between another function named method2. -Steve
Jun 14 2016