K
keith.thornhill
hey all, got a problem here using Visual basic .net 2005
i have two pairs of base/derived classes. lets call them Base/Derived
and BaseStruct/DerivedStruct.
i want to be able to instantiate a DerivedStruct in my Derived class,
but have the instance of it be accessible from both the Base class (as
BaseStruct) and Derived class (as DerivedStruct)
this is the kind of code i'm looking to be able to use
----------------------------------
class Base
'declare it
protected myStruct as BaseStruct
' access it
myStruct.SomeBaseMember()
end class
class Derived
inherits Base
'instantiate it
myStruct = new DerivedStruct
'access it
myStruct.SomeDerivedMember
end class
----------------------------------
i can get something similar working, but only if, in my derived class,
i use CType() to cast myStruct to the Derived type before i try to
access any derived members of the DerivedStruct
i REALLY would like the >compiler< to see that when i reference
myStruct from within the Base, to give me access to the BaseStruct
members and when i reference myStruct from within Derived, to give me
access to the DerivedStruct members. and for both examples, i want it
all to be accessing one instance of that DerivedStruct
i've tried puting "protected myStruct as DerivedStruct = new
DerivedStruct" in my Derived class, but this shadows the base myStruct
so they aren't the same thing in memory.
is this possible? thanks!
i have two pairs of base/derived classes. lets call them Base/Derived
and BaseStruct/DerivedStruct.
i want to be able to instantiate a DerivedStruct in my Derived class,
but have the instance of it be accessible from both the Base class (as
BaseStruct) and Derived class (as DerivedStruct)
this is the kind of code i'm looking to be able to use
----------------------------------
class Base
'declare it
protected myStruct as BaseStruct
' access it
myStruct.SomeBaseMember()
end class
class Derived
inherits Base
'instantiate it
myStruct = new DerivedStruct
'access it
myStruct.SomeDerivedMember
end class
----------------------------------
i can get something similar working, but only if, in my derived class,
i use CType() to cast myStruct to the Derived type before i try to
access any derived members of the DerivedStruct
i REALLY would like the >compiler< to see that when i reference
myStruct from within the Base, to give me access to the BaseStruct
members and when i reference myStruct from within Derived, to give me
access to the DerivedStruct members. and for both examples, i want it
all to be accessing one instance of that DerivedStruct
i've tried puting "protected myStruct as DerivedStruct = new
DerivedStruct" in my Derived class, but this shadows the base myStruct
so they aren't the same thing in memory.
is this possible? thanks!