10-02-2013 11:44 AM
I've been playing with lvoop for 4 or 5 months now, and in general I like it very much, but I've repeatedly wanted to build classes that know something about who owns them and I can't figure out how to make this happen.
The simple example I've been thinking about is imagine having a person class which contains a car class. Now say that I get an instance of a car class and I want to ask it who its owner is. In C++, I'd do this by giving the car class a pointer to the person class it belongs to. (Of course you have to worry about car objects that don't belong to anyone in which case the pointer has to point to NULL.)
I've tried copying this idea by giving the car class a data value reference to a person class, but when I dereference the reference using an in place loop and call a method on it I get data from the moment the reference was made and not the current data of the person class.
I realize this is sorta breaking data flow so maybe it's not possible on purpose?
10-02-2013 12:47 PM
This is probably happening because the private data of the car class is not stored as a reference. What this means is that when you call methods of the class on the wire it updates values and outputs them back to the wire. Branches of this object create independent memory spaces and do not link back to the initial creation.
Essentially what you want to do is use a class architecture which has a DVR as the private data and explicitly create constructors and destructors for it. In this way once you have initialized this class with the constructor whenever you branch the wire each copy still references the same reference and can operate on the same data.
This is mentioned briefly in this article: http://www.ni.com/white-paper/3574/en/
And there are some examples in the example finder relating to this as well.
10-02-2013 01:42 PM
@Scot18 wrote:
I've tried copying this idea by giving the car class a data value reference to a person class, but when I dereference the reference using an in place loop and call a method on it I get data from the moment the reference was made and not the current data of the person class.
Yes, LVOOP uses value based references, and when you split the wire to write the owner you created a data copy. The function you're after requires you do use a DVR for all class functions in which case you'll get reference based OOP, which is more familiar coming from text based OOP.
It just so happens that G# uses that approach, take a look at it. 🙂
/Y