Does this help clear up your confusion?
#include <stdio.h>
#include <stdlib.h>
class A {
public:
A() {}; void memberfunc1(){printf("A:memberfunc1\n");}
void memberfunc2(){printf("A:memberfunc2\n");}
};
class B : public A
{ A *pA;
public:
B()
{
pA = new A[3]; };
~B()
{
delete [] pA; }
void showAll()
{
int i;
for (i=0; i<3; i++)
{
printf("-------- Callling member functions of pA[%d]--------\n", i);
pA[i].memberfunc1();
pA[i].memberfunc2();
}
}
};
int main()
{
B *pB = new B[2];
printf("=======***** Calling member function of pb[0] ****=======\n");
pB[0].showAll();
printf("=======***** Calling member function of pb[1] ****=======\n");
pB[1].showAll();
delete [] pB; }
Also, to address your questions:
Is this possible? ( A[0] call memberfunction1, A[1] & A[2] call memberfunction2)
Sure is, compile the code and give it a whirl.
What do these two pointers actually point to?
They're no more than a pointer to the first element in the array. Because of the way they're (the arrays) declared, the compiler doesn't know how many elements are in each array.
Consider the following snippet:
char str1[] = "This is a 24 char string";
char *str2 = strdup(str1);
char *str3 = new char[strlen(str1)+1];
strcpy(str3, str1);
printf("sizeof(str1) = %d\n", sizeof(str1) );
printf("sizeof(str2) = %d\n", sizeof(str2) );
printf("sizeof(str3) = %d\n", sizeof(str3) );
Output:
sizeof(str1) = 25
sizeof(str2) = 4
sizeof(str3) = 4
You need to be careful with how you interpret these results - while it's true that all three of them are pointers, the behaviour of the sizeof operator muddies the water somewhat. I won't try to explain, for fear of making them even murkier..
Hope this helps alleviate, rather than adding to your confusion. :)