pointer-to-pointer of derived class in multiple inheritance

Posted by Abdul jalil on Stack Overflow See other posts from Stack Overflow or by Abdul jalil
Published on 2010-06-18T10:08:37Z Indexed on 2010/06/18 10:13 UTC
Read the original article Hit count: 325

Filed under:
|

i have 3 classes A,B and C. C is derived from A and B. i get pointer to pointer of class C and cast to A** , and B ** , the variable that hold the the B** has the address of A** in my example B ** BdoublePtr hold the address of A** .i am using the following code

#include "conio.h"
#include "stdio.h"
#include "string.h"
class A{
public:
A()
{
strA=new char[30];
strcpy(strA,"class A");
}
char *strA;

};

class B
{

public:
B()
{
strB=new char[30];
strcpy(strB,"class B");
}
char *strB;

};

class C :public A, public B
{

public:
C()
{
strC=new char[30];
strcpy(strC,"class C");
}
char *strC;

};

int main(void)
{

C* ptrC=new C();
A * Aptr=(A*)ptrC;
printf("\n class A value : %s",Aptr->strA);

B * Bptr=(B*)ptrC;
printf("\n class B value :%s",Bptr->strB);


printf("\n\nnow with double pointer ");
A ** AdoublePtr=(A **)&ptrC;
Aptr=AdoublePtr;
printf("\n class A value : %s",Aptr->strA);


B *
BdoublePtr=(B **)&ptrC;
Bptr=*BdoublePtr;
printf("\n class B value : %s",Bptr->strB);


getch();
return 0;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about c