у меня есть 3 класса A, B и C. C получен из A и B. Я получаю указатель на указатель класса C и приводим к A **, и B **, переменная, которая содержит B ** имеет адрес A ** в моем примере B ** BdoublePtr содержит адрес A **. Я использую следующий код
#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;
}