0

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?

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by Ancient Dragon
0

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();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.