I read about this somewhere, but I completely forget where, so maybe someone could help me. This problem deals with inheritance and casting. As an example, I'll use, class A and class B which is a subclass of A.
You can't cast A into B, because an A is not a B, but a B is an A, so you can cast it, however you will lose certain data. For example:Code:class A { int num; } class B : public A { int num2; }
That should work, but anA is not a B so it can not hold the num2 value, so data would be lost in the conversion. But I read a way to get around this, using pointers or something. Anyone have any idea?Code:A anA; anA.num = 5; B aB; ab.num = 1; ab.num2 = 2; anA = (A)aB;



LinkBack URL
About LinkBacks


