Page 1 of 1

Class member overloading..?

Posted: Sat Feb 03, 2007 4:04 pm
by dwfait
Hi..I'm wondering if you can do something like this:

Code: Select all

class a
{
     public:
          ISceneNode* Node;
}


class b : public a
{
      public:
            ICameraSceneNode* Node;
}



I have code like that to similar effect in my project, and it compiles fine, but whenever a function is called that addressed the ICameraSceneNode Node, the program "encounters an unexpected error and has to close".

If it's not possible, can anyone give any suggestions to workarounds?

Posted: Sat Feb 03, 2007 6:47 pm
by sudi
You could do the following:

Code: Select all

class a
{
    public:
        a(ISceneNode* Node)
        {
            m_Node = Node;
        }
        ISceneNode* m_Node;
};

class b : public a
{
    public:
        b(ICameraSceneNode* cam) : a(cam)
        {
            m_cam = cam;
        }
        ICameraSceneNode* m_cam;
};
That way u can use the scenenode like a scenenode out of the base class and the camera from the otherone.

Posted: Sun Feb 04, 2007 12:29 pm
by hybrid
The error is due to the elements being pointers which you have to set to pointing to existing objects. Otherwise each access will crash your app.