Re: [Vala] Static property



On 22/01/2008, gege2061 <gege2061 redaction-developpez com> wrote:
Hi,

I wan't implement singleton pattern but I have compilation error :

  public static Singleton* instance
  {
    get
    {
      if (_instance == null)
      {
        _instance = new Singleton ();
      }
      return _instance;
    }
  }

In short, it isn't actually possible to have a "static property".
Properties belong specifcally to an a instance of a GObject derived
class.  You can actually return class (static) data when a property is
requested, but you still need an instance of the type in order to
execute the getter method.

In this case I would suggest write the method to get the instance by hand.

As to the error message, I'm not sure why that happens either - if you
remove that bad line you'll find value won't complain at all, but the
generated C won't compile.  I guess the strangeness is probably down
to using pointers - unless you have a specific need, I would just use
references.
-- 
Phil Housley



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