I have a base class (call it A) from which I have several derived classes. A has a CArray<A*> data member (dynamic array of pointers to A objects). When adding an object of B (class derived from A), none of B's data members show up when the object is accessed from the CArray of the first A object. Apparently, the B object is not being copied somehow. I'm currently using this code:

class A
{
     A() {}

     void AddChild(A* child)
     {
           m_aryChildren.Add(child);
     }

     CArray<A*> m_aryChildren;
}

class B : public A
{
      B()
      {
            A::AddChild(new A());
      }
}

// ....

A aobject();
aobject.AddChild(new B(5, 7));
int size = aobject[0].m_aryChildren.GetSize();

the 'size' variable should be 1. Yet it's showing up as zero, as if the B object I passed never had any of its data members set. Does anyone know what the problem is?

Apologies, minor error in the code. Problem still outstanding.

class A
{
     A() {}

     void AddChild(A* child)
     {
           m_aryChildren.Add(child);
     }

     CArray<A*> m_aryChildren;
}

class B : public A
{
      B()
      {
            A::AddChild(new A());
      }
}

// ....

A aobject;
aobject.AddChild(new B());
int size = aobject[0].m_aryChildren.GetSize();

[edit]I deleted my comment[/edit]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.