digitalmars.D.learn - Instantiating an Object with the Same Object as an Argument?
- Ron Tarrant (22/22) Apr 17 2019 I've come across this a few times in the wrapper code for GtkD
- Adam D. Ruppe (5/8) Apr 17 2019 Those aren't the same thing! One is Adjustment, the D wrapper
- Adam D. Ruppe (7/7) Apr 17 2019 btw if you haven't seen my version of the gtk-d docs, check it
- Ron Tarrant (3/12) Apr 17 2019 Ah! Thanks for clearing that up, Adam. I shall go blush now for
I've come across this a few times in the wrapper code for GtkD where one of the constructors for an object takes an argument of the same type the constructor produces. For instance, one of the Adjustment constructors looks like this: public this(GtkAdjustment* gtkAdjustment, bool ownedRef = false) { this.gtkAdjustment = gtkAdjustment; super(cast(GObject*)gtkAdjustment, ownedRef); } I have a vague memory of finding out how to use this type of constructor from a while back, but I can't remember how. And if I did find out, I neglected to take notes, apparently (shame on me) but I may also have dreamed it. And I can't find a cogent example. At first glance, this form of constructor seems impossible to use. I mean, how can I instantiate an object passing the object (which doesn't exist) as an argument? Or is this not actually a constructor? Or maybe there's some magic going on here that I'd understand if I knew D better? I keep running across this, so I'm hoping someone can give me a leg up.
Apr 17 2019
On Wednesday, 17 April 2019 at 14:49:33 UTC, Ron Tarrant wrote:For instance, one of the Adjustment constructors looks like this: public this(GtkAdjustment* gtkAdjustment, bool ownedRefThose aren't the same thing! One is Adjustment, the D wrapper class, and the other is GtkAdjustment*, the C structure pointer. This constructor is for cases when you have an existing object made via the C api and you want the D wrapper to adopt it.
Apr 17 2019
btw if you haven't seen my version of the gtk-d docs, check it out: http://gtk-d.dpldocs.info/gtk.Adjustment.Adjustment.html It does various cross-referencing the official versions don't, among other things. You can see the GtkAdjustment there is not linked, because it is the C version, whereas references to gtk.Adjustment are links to the D classes.
Apr 17 2019
On Wednesday, 17 April 2019 at 15:05:22 UTC, Adam D. Ruppe wrote:On Wednesday, 17 April 2019 at 14:49:33 UTC, Ron Tarrant wrote:Ah! Thanks for clearing that up, Adam. I shall go blush now for not reading more closely.For instance, one of the Adjustment constructors looks like this: public this(GtkAdjustment* gtkAdjustment, bool ownedRefThose aren't the same thing! One is Adjustment, the D wrapper class, and the other is GtkAdjustment*, the C structure pointer. This constructor is for cases when you have an existing object made via the C api and you want the D wrapper to adopt it.
Apr 17 2019