Creating a Parent/Child relationship with objects
<p>Okay, so I am having some troubles in creating a Parent/Child relationship. The easiest way I can explain this is having an object, with a reference (or pointer) to another object of the same type, and then an array of children references (or pointers) to more objects. The object should have functions like .getChildren, .addChild, .removeChild, .getParent, .changeParent.
I'm having a horrible time with the pointers, and if anyone could help with the code that'd be great. 
Also, in case anyone is curious, I'm going to use this approach with 3D models. The base model (parent) will be the center of the object, all children can move freely, and when the parents moves, it causes the children to move.</p>

<p>Code:</p>

<pre><code>class Base {
  protected:
    Base* parent;
    std::vector&lt;Base*&gt; children;

    std::string id;

    POINT pos, rot;
  public:
    Base (void);
    Base (std::string);
    Base (POINT, POINT, std::string);
    Base (const Base&amp;);
    ~Base (void);

    POINT getPos (void);
    POINT getRot (void);

    Base getParent (void);
    Base getChildren (void);

    void addChild (Base&amp;);
    void removeChild (Base&amp;);
    void changeParent (Base);

    void move (int, int);
    void rotate (int, int);

    void collide (Base);
    void render (void);
};

Base::Base (void) {
    this-&gt;id = getRandomId();
    this-&gt;pos.x = 0; this-&gt;pos.y = 0; this-&gt;pos.z = 0;
    this-&gt;rot.x = 0; this-&gt;rot.y = 0; this-&gt;rot.z = 0;
};

Base::Base (std::string str) {
    this-&gt;id = str;
    this-&gt;pos.x = 0; this-&gt;pos.y = 0; this-&gt;pos.z = 0;
    this-&gt;rot.x = 0; this-&gt;rot.y = 0; this-&gt;rot.z = 0;
};

Base::Base (POINT p, POINT r, std::string str) {
    this-&gt;id = str;
    this-&gt;pos = p;
    this-&gt;rot = r;
};

Base::Base (const Base&amp; tocopy) {
    this-&gt;parent = tocopy.parent;
    this-&gt;children = tocopy.children;
    this-&gt;id = tocopy.id;
    this-&gt;pos = tocopy.pos;
    this-&gt;rot = tocopy.rot;
};

Base::~Base (void) {
};

void Base::changeParent (Base child) {
    *(this-&gt;parent) = child;
};

int main (void) {
    POINT p;
    p.x=0;p.y=0;p.z=3;
    Base A;
    Base B(p, p, "Unique");
    printf("A.pos.z is %d and B.pos.z is %d\n", A.getPos().z, B.getPos().z);
    B.changeParent(A);
    printf("B.parent.pos.z %d should equal 0\n", B.parent-&gt;getPos().z);
</code></pre>

<p>The error I get with the code is: error C2248: 'Base::parent' : cannot access protected member declared in class 'Base'
Also, if I make everything public, it'll compile fine, but then it crashes on run.</p>

<p>Note: I didn't copy all of the code, just what I thought would be relevant.</p>

<p>EDIT: Full dump of the error:</p>

<pre><code>(152) : error C2248: 'Base::parent' : cannot access protected member declared in class 'Base'
    (20) : see declaration of 'Base::parent'
    (18) : see declaration of 'Base'
</code></pre>
