Simple OOP Casting Question

atmosphere1212

Active member
Joined
Aug 31, 2004
Messages
42
Is it possible to cast down to an object that doesnt exist?

ie

temp = (SomeClass)objInstance

where objInstance is an instance of a parent object, and SomeClass is the object I want. Note that objInstance is not an instance of SomeClass, just its parent
 
atmosphere1212 said:
Is it possible to cast down to an object that doesnt exist?

ie

temp = (SomeClass)objInstance

where objInstance is an instance of a parent object, and SomeClass is the object I want. Note that objInstance is not an instance of SomeClass, just its parent

If temp is declared as the parent object then yes, you can make it equal to a sub-class. In fact you can always implicitly cast to a base class i.e. you dont even need the (...) bit.
 
Back
Top