Topic: casting across inherited parents


Author: eddy@morgan.com (Edward Eldridge)
Date: 1995/04/19
Raw View
what should the following produce?

#include <iostream.h>

class base2 {};

class base
{
public:
    base() : something(1) {}
    int value() {return something;}
private:
    int something;
};

class derived : public base2, public base {};

void main()
{
 derived *d=new derived;
 cerr<<"d->side()="<<d->value()<<endl;
 base2 *b2=(base2*)d;

 base *b=(base*)b2;
 cerr<<"b->side()="<<b->value()<<endl;
}