Re: [Vala] class constructor not being called



2013/3/16 Albert Hopkins <marduk letterboxes org>



On Sat, Mar 16, 2013, at 12:15 PM, Jonas Kulla wrote:
[...]
Hi,

Your function 'noop()' is declared static, hence no instance is required
to
call it.
Class constructors are called on the first construction of an instance,
ie.
when you do 'new MyClass();' .

Jonas

I'm looking to create a static class (or whatever the correct way to to
this in vala).  Basically I need a class that will have all static data,
so I won't require to initialize the class.  It will have some static
methods and a HashMap.  I'm trying to initialize the HashMap.  I thought
a class/static constructor would do the trick.  Apparently this is not
the preferred method.  Do you know what is?

thanks,
-a


Hm, a since a class with only static methods isn't really more than just
a bunch of functions/variables namespace'd together, I don't quite see the
point in it to begin with. Anyway, what I'd do in your case is to either
require
the user of your class/functions to call an initial 'MyClass::init()', or
to do
a check at the beginning of each function and init the respective variables.

Jonas



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]