Write variable from other function

Dicebot public at dicebot.lv
Fri Feb 28 08:07:30 PST 2014


On Friday, 28 February 2014 at 15:59:41 UTC, Suliman wrote:
> Oh thanks! I had forgot that I should declarate it's in class.
> But what about return type? Look like that DMD want that I 
> declarate some bool value in constructor. It's get me next 
> error: "Error: need 'this' for 'isConfigExist' of type 'bool()'"
>
> http://www.everfall.com/paste/id.php?qs2lsozrd3k7

Methods that can be called without any specific instance ("this") 
must be declared static too.

'Config` defines a class, which is a type. Normally you want to 
create an instance of the type (object of the class) before using 
it and each object has new set of variables.

When you declare variable static it makes it shared between all 
instances of that class, allowing to use it without any specific 
instance. When you declare method as static you say to compiler 
that it is not going to use any non-static fields of the class 
(normally available via "this" pointer) and make it possible to 
call it as `Config.method`.


More information about the Digitalmars-d-learn mailing list