This widget could not be displayed.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing subclass data when parent class is part of private data of another class.

I am working up an OOP test program and have a problem with data access.

I have the following classes defined:

General Test

General Report

Specialized Test

Specialized Report

 

The Specialized Test and Specialized Report are subclasses of General Test and General Report, respectively.

The General Test class contains a General Report class instance as part of it's private data.

 

Specialized Test writes a Specialized Report to its parent class data on initialization. The Specialized Report contains additional data items in its private data.

 

I have a method for Specialized Test where I first access the Report object stored in the General Test private data, then try to access the private data of the Specialized Report, that should be returned.I get a class mismatch, as the General Test accessor does not know it is returning a Specialized Report.

 

Should I simply typecast the returned report to the more specific class before trying to access the subclass data as shown below, even though it will already be the more specific class?

 

Thanks,

 

Josh

 

 

0 Kudos
Message 1 of 2
(2,592 Views)

I don't see your image - maybe it just hasn't finished uploading yet - but if I'm understanding correctly, using To More Specific Class (not Type Cast) is a fine solution here. It's reasonable to use To More Specific Class to get the wire type to match the type of data that you know it will carry when the compiler cannot make that determination for you automatically.

0 Kudos
Message 2 of 2
(2,578 Views)