linux - Vala files import -
i have problem when work properties in separated files in vala language
the main.vala file is
using teste; using cagado; static int main(string[] args) { gui gui = new gui(); stdout.printf("%d\n", gui.idade); return 0; }
the hellovala.vala is:
namespace teste { public class person : object { private int _age = 32; public int age { { return _age; } set { _age = value; } } } }
the cagado.vala is:
using teste; namespace cagado { public class gui : object { person _person = new person(); _person.age = 35; private int _idade; public int idade { { return _idade; } set { _idade = value; } } } }
when compile code, compile gives me message error:
cagado.vala:9.15-9.15: error: syntax error, expected identifier _person.age = 35; ^
i program in c# , not happened in c# oriented object system. explain this?
the problem this:
public class gui : object { person _person = new person(); _person.age = 35; // <-- ...
you can't put arbitrary code inside of class itself, declarations. need like
public class gui : objects { person _person = new person(); construct { _person.age = 35; }
you modify add constructor person class:
namespace teste { public class person : object { private int _age = 32; public int age { { return _age; } set { _age = value; } } public person(int age) { glib.object (age: age); } } }
then do
public class gui : object { person _person = new person(35);
Comments
Post a Comment