Suppose we have following relation between class A and class B:
class A {
public:
A();
A(const A&);
A& operator = (const A&);
protected:
// data members
};
class B : public A {
public:
B();
private:
// data members
};
And as shown below, suppose we have an array of 5 derived class B objects - bArr. We have a requirement to create an array of base class A objects - aArr - from members of bArr by invoking only the class A copy constructor. We can not invoke class A default constructor and assignment operators.
B* bArr = new B[5];
A* aArr;
This depiction shows our intent. You can think of each object of class B made of data from both A and B - {AB}. We only want to copy the A-part of each object in bArr to aArr.
Which one of the following choices can achieve what we want to do?