hfettig Posted August 15, 2008 Report Share Posted August 15, 2008 I know this question sounds strange and is probably not well phrased. So here is my problem: I have a parent class Setup.lvclass. From this I inherit multiple classes, e.g. LivSetup.lvclass, TlmSetup.lvclass, etc. The parent class has three dynamic dispatch functions: ReadFromIniFile.vi, WriteToIniFile.vi, WriteToConfigFile.vi All classes have as their private data a cluster called Setup Data and a string called Ini File Section. Now currently I have an override function in each child class for each of the three dynamic dispatch functions. This allows me to bundle up my child classes into an array and run a for loop on the dispatch functions. This part works really well. Now I noticed that my ReadFromIniFile.vi and WriteFromIniFile.vi are identical for all child classes. The only difference being the contents of the Setup Data cluster. So my thought was to implement the same code in the base class and remove the overrides. Now the problem is that in order to make the code work in the base class I have to give it the same controls in the private data. Therefor now the functions always save that data to the ini file regardless of what child class I wire to it. Is there any way around that? Can I cast the data dynamically to the data type of the child class that is wired to it? Or am I just completely misusing the inheritance here ;-) Any help is appreciated. For now I will continue with the identical overrides. Cheers, Heiko Quote Link to comment
shoneill Posted August 15, 2008 Report Share Posted August 15, 2008 You can't cast a parent as a child unless the true class type of the object is in fact a child (having been previously up-casted). Your solution is to implement the code in the parent and then call it within the child, so logically the opposite to what you're questioning. Inheritance works in one way only. Why not remove the data from the children and simply use the parent implementation (Call parent method)? Shane. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.