Down cast in a derived hierarchy
Latest Revision
Hi people, I've ran into a problem where i wanna downcast a object of a different type to a object longer down in a derived hierarchy, i think the best way is just to show some simple code:
class mammal {}
class dog : mammal{}
class cat : : mammal{}
class program
{
public main()
{
mamal m = new mamal();
cat c = new cat();
c = (cat)m;
c = (m as cat);
}
}
as seen i wanna give a cat object a mammal object/have all the info in the mammal putted into the cat object, which is derived from mammal, i tried implicit operators but saw that this is invalid to do in derived classes. so is there a way to do this without doing everything manually?
thanks - Jackie
Posted 16-Nov-12 12:06pm
by
Jackie00100.