Why are my two classes sharing variables? C++

Started by
24 comments, last by BHXSpecter 10 years ago

I think i found out the bug today guys. Basically what happened was that i declared an array of octorocks:
OCTOROCK octorocks[4];
But what i did wrong was that initialized it like this
octorock[1].x =......
octorock[2].x =......
octorock[3].x =......
octorock[4].x =......
What i did wrong is that i didnt access octorock[0] and did a memory violation by going out of bounds in tbe array with octorock[4].


Don't worry. Mistakes like this are quite common. That's why I tend to look to see if I've made silly mistakes first when debugging. I hate it when I end up making major changes when the original bug just turns out to be a missing minus or something. Glad you found the answer.

Learn all about my current projects and watch some of the game development videos that I've made.

Squared Programming Home

New Personal Journal

Advertisement

Just curious. You set a lot of class variables as private. Any reason why you do that?

wat

In a simple answer, data hiding. It is usually common practice to make class members (variables) private and only allow access by way of constructors(mainly for initializing the class object) and class methods (functions).

Yes.. Except he's asking why they are private, not public. I guess it was a typo.

"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "

My apologies. Meant to quote just Buckeye and didn't realize I had quoted your post. It wasn't aimed at you. Again, I'm sorry, I should have paid closer attention to what I was quoting before submitting it.

I think i found out the bug today guys. Basically what happened was that i declared an array of octorocks:
[...]
What i did wrong is that i didnt access octorock[0] and did a memory violation by going out of bounds in tbe array with octorock[4].

So it was indeed bad pointer management!
These kind of symptoms are really common in these cases.

Thought Id show everybody how it looks now:

The final version will be posted in the announcements section once I complete it, so stay tuned!

Looking good ISDCaptain01. I'll keep a look out on the announcements section for sure.

This topic is closed to new replies.

Advertisement