Hello All,
I have a project I am currently working on using VB .NET and VS 2005. Basically one of my classes maintains a collection of various objects all derived from a base class, but different. I want each of these derived classes to have a common method, but the paramaters for the method will vary.
Example, here is a cut down version of the base class and derived classes and what I want them to do.
Class clsString
public mustoveride sub AddPoint(index as integer, pnt as clsPnt)
End class
Here are some versions of the derived classes.
Class clsString3D
inherits clsString
public overrides sub AddPoint(index as integer, pnt as cls3d)
'do some other stuff here
End class
Class clsString6D
inherits clsString
public overrides sub AddPoint(index as integer, pnt as cls6d)
'do some other stuff here
End class
My program returns the object in this manner
Public function getString(byref name as string) as clsstring
getstring=string.item(name)
end function
I then call the function like this
Dim STR as clsstring
dim P6 as new cls6D
p6.setvals(5,7,34.6,45,3)
str=MDL.getString("MC01") 'this would in a working version return a string of clString6D
Str.AddPoint(4, P6)
Now I realise that you cannot override the function if the function signature is not the same, but shadowing doesn't seem to work either. Could someone please explain to me correct way for me to code what I want to do, or even if it is possible.
Regards,
Martin Duke