Error Averted!

Posts 1–10 of 10 · Page 1 of 1
Error Averted!
So I had a real doosy, but my uber 1337 skills helped me to fix it. within 30 min. It was a lot of code to sift through (500 lines) so don't hate. ;l

I had a set up like this
Code:
//Assuming B has already been declared and there are no compile errors.
class A
{
      B** arrayofB;
      int num_of_Bs;
      A()
      {
           B newB(someargs);
           arrayofB = new B*[10];
           memset(arrayofB+1,0,10-1);//zeros memory of my array (hint: not the prob)
           arrayofB[0] = newB;
           num_of_Bs = 0;
      }
      void Render()
      {
           for(int i = 0; i <= num_of_Bs; i++)
           arrayofB[i]->Render();
      }
};
Lol. a dollar to anyone who can figure out what the problem would be if I called Render();

If no one figures it out I'll tell you the answer tomorrow! =P
You allocate the space for 10 arrays of arrays of B, but you never allocate the object themselves. You set the first element that is a pointer, to a temporary object.
You allocated the array that would point to the arrays, but never the children. It doesn't look like you want that at all, how you did render was one-dimensional.Use a vector of pointers, or just a vector. So, most likely the problem if you called render would be that you were doing it on a nulled object.
Dollar please.
Why06 got owned.

Faith +1
Oh man you got it! D:

Fine a deals a deal. I am a man of my word. Hold on I have to set-up a PayPal account. ;l

EDIT: oh yeah there's more stuff in my actual render function. that was just to make the answer easier to see.... still didn't think someone would get it forst day though. :P
It's cool bro, I don't have a paypal either. I was just joking bout the dollar.
Quote Originally Posted by Faith View Post
It's cool bro, I don't have a paypal either. I was just joking bout the dollar.
xFaith... you know you gotta reply quicker... I already made it now... :l

who do I give this dollar to?
Hmmm.... I am starting a fund for me to get a new violin (don't ask what happened to my old one)
~
Okay, guess the song yet?
Or you know, You can give the dollar to me >_> If you had these contests more often I might stick around in MPGH ^_^

But man, am I rusty. Took me a while to even understand that code >_<.

Wait, but, I don't see anything wrong with it. Sure it seems you meant to allocated 10 B*, and only allocated one, but you only try to call the render from one anyway? if you changed num_of_b then maybe it would be a problem. . . I dunno. I am super rusty, and idiotic.
I didn't get it ~ only natural since I couldn't figure what that section of code was suppose to do...
Posts 1–10 of 10 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us