Write variable from other function

Mike Parker aldacron at gmail.com
Fri Feb 28 08:26:26 PST 2014


On 3/1/2014 1:16 AM, Suliman wrote:
>> 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`.
>
> Thanks! I know about static, but now I need experience to work with
> class constructor. So now I can't understand what I can do with error:
> "Error: need 'this' for 'isConfigExist' of type 'bool()'"

Here, 'this' is not referring to a constructor, but to an instance of 
the class. It means you are trying to call isConfigExist but haven't 
created an instance of Config yet.

auto config = new Config( "exepath", "configPath" );
writeln( config.isConfigExist() );


More information about the Digitalmars-d-learn mailing list