problems virtually inherited classes
We have 4 c++ classes
class base{
int opcode;
Quote:
};
class derived1:public virtual base{
char * filename;
char * mode;
Quote:
};
class derived2:pubic virtual base{
unsigned short block;
Quote:
};
class final:public derived1, public derived2{
Quote:
};
we have created a buffer of type unsigned char.
now we want to write the class derived1 to the buffer.
so we use a pointer to the class derived1 and then type cast the base
address of the buffer to the class derived1;
this is how we are doing it
#define mtod (m, t) ((t)(m))
unsigned char buffer[50];
derived1 * drv1_ptr;
drv1_ptr = mtod(buffer, derived1 *);
and now when we try to write to data to the buffer using
drv1_ptr->opcode = somevalue;
drv1_ptr->filename = new char[10];
drv1_ptr->mode = new char[10];
the code compiles but when it tries to write to the global buffer it
gives an segmetation fault......
we have tried the same logic with classes which are not virtually
inherited and works fine .....
kindly help
tushar