LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW OPP - To More Specific and To More Generic

I am getting errors when I cast classes to a child? Any thoughts? 

Dealcs2_1-1679531435935.pngDealcs2_2-1679531458527.png

 

0 Kudos
Message 1 of 3
(788 Views)

I guess it is because you instantiate an instance of the parent class. You cannot downcast to a child class.

Reference: How To Properly Cast Object to Child Class? - Object-Oriented Programming

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 2 of 3
(778 Views)

@ZYOng wrote:

I guess it is because you instantiate an instance of the parent class. You cannot downcast to a child class.

Reference: How To Properly Cast Object to Child Class? - Object-Oriented Programming


Spot on!

 

The use case for the transforms are typically:

You create a basic class, e.g. Instruments

You create specific children, as DAQ, DMM and so on. Which have some added methods that are specific to their group.

You create a list of instruments, which needs to be of Instruments class to handle all.

You grab an instrument by name from your list and get the Instrument ref.

You need to use one of the specific functions on your DMM, which is listed as an Instrument:

- To more specific allows you to use the function in the code.

 

Alternatively you bulk/bloat your base class with all methods from all subclasses to avoid the conversion and end up with lots of unnecessary methods and code stink. This also forces all to have the same connector pane if they have the same name, how illogical it might be.

 

Choose your poison, sometimes it's sort of impossible to do right.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 3
(718 Views)