Original Post
Ok, I have a base class with a variable - Lets call it Alive - and then I have a bunch of derived classes. If I have a void pointer to one of the derived classes, can I prototype it as the base class and read the Alive variable without any horrible repercussions?
#include <iostream.h>
class BaseClass
{
public:
int Alive;
};
class DerivedClass : public BaseClass
{
public:
int a;
int b;
int c;
};
void main( void )
{
DerivedClass dc;
dc.Alive = 10;
void *pdc;
pdc = &dc
cout << ((BaseClass*)(pdc))->Alive;
}
|