[Vala] Static property



Hi,

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

using GLib;

public class Singleton : Object
{
  static Singleton* _instance = null;

  private Singleton ()
  {
  }

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

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

  public static int main (string[] args)
  {
    Singleton* s = null;
    s = Singleton.get_instance ();
    s = Singleton.instance; // line 35
    return 0;
  }
}

And compilation command :

$ valac singleton.vala
/home/gege2061/test/vala/singleton.vala:35.7-35.7: error: Assignment: Invalid callback assignment attempt
Compilation failed: 1 error(s), 0 warning(s)

I don't undestand my error :(

--
Nicolas Joseph

Responsable de la rubrique GTK+ de developpez.com

http://nicolasj.developpez.com


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