Re: [Vala] private fields vs bodyless properties
- From: Yu Feng <rainwoodman gmail com>
- To: "Jaap A. Haitsma" <jaap haitsma org>
- Cc: vala-list <vala-list gnome org>
- Subject: Re: [Vala] private fields vs bodyless properties
- Date: Fri, 30 May 2008 04:28:46 -0400
On Fri, 2008-05-30 at 06:57 +0200, Jaap A. Haitsma wrote:
On Fri, May 30, 2008 at 2:05 AM, Hans Vercammen <hveso3 gmail com> wrote:
Now the construct keyword for properties in the class constructor
arguments is being deprecated, I started to adjust some things and
stumbled upon some implementation questions.
While "private int foo { get; set; }" does not make much sense and
should better be optimized to "private int foo;", assignment of the
private field foo in the constructor with a constructor argument is not
possible at the moment, only property assignments are allowed. There
might be a good reason for this, but I could not find any reference, so
just a quick question here.
The reason for this is that the objects are gobjects and these are
created by a g_object_new call [1]. That function can only set
properties. So you need to have a property if you want to pass data to
your constructor
Jaap
However the following code is perfectly fine;
MyObject * my_object_new(int my_value){
MyObject * myobject = g_object_new(TYPE_MY_OBJECT, NULL);
MyObjectPrivate * priv = MY_OBJECT_GET_PRIVATE(myobject);
priv->my_value = my_value;
}
(I think I am also using this when writing c programs)
A .new method is nothing more than a static member of the class to
create an object. I don't think we should think of it as an constructor.
After all, the static _new member is kind of in the GType level, and
'constructors' is a different story in the GObject level.
Regards,
Yu
[1] http://library.gnome.org/devel/gobject/unstable/gobject-The-Base-Object-Type.html#g-object-new
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]