Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Useful

Problem with children

This topic is 5858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to get a decent way to render all my OO classes. Using one of the Columns on this site I implemented this code(its not the TOTAL code, but it should be enough for someone to point out what im doing wrong) The problem is that my iterator in Render::updateScene always asserts and i dont know what is the matter. Any help is appreciated
  
class Object
{
public:
 Object() {}
 ~Object() {}
 void addChild(Object* pChild)
 {
  assert(pChild);
  pChild->setParent(this);
  children.push_back(pChild);
 }

 std::vector<Object*>* getChildList()
 {
  return &children;
 }
protected:
 std::vector<Object*> children;
 GameObject* parent;
private:
 void setParent(Object* pParent)
 {
  parent = pParent;
 }
};

void Render::updateScene(Object* pObject)
{
 // Base case for the recursion

 if (pObject == NULL)
  return;
 else
 {

  pObject->update();
  pObject->draw();
// begin problem code

  std::vector<pObject*>::iterator it = pObject->getChildList()->begin();
  assert(it);
  while (it != pObject->getChildList()->end())
  {
   updateScene(*it);
  }
// end problem code

 }
}
  
[edited by - useful on June 7, 2002 5:36:42 PM] [edited by - useful on June 7, 2002 5:37:53 PM]

Share this post


Link to post
Share on other sites
Advertisement
Just your topic, is quite misleading lol...

Slow and steady wins the race.

Share this post


Link to post
Share on other sites
I agree, yet I dont even know how to explain the problem. So I took my english 101 approach =)

Share this post


Link to post
Share on other sites
sorry, thought i commented the problem properly. It asserts after declaring the iterator in Render::updateScene.

I dont understand if the iterator is screwed or if the vector of objects is being passed incorrectly.

Share this post


Link to post
Share on other sites
assert (it) doesn''t make any sense. If you''re trying to make sure that your container isn''t empty, you should:
assert (pObject->getChildList()->end () != it);
assert (*it) will assert the contained object (a pointer) is not null.
I''m not sure which of those is what you meant.

Share this post


Link to post
Share on other sites
i figured it out, i wasnt accually using the iterator (stupid me) and asserting it doesnt help because it is an iterator.

thx for the suggestion, it helped alot. code works now.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!