Joey wrote:
i dont understand any of the code that you typed in.
The idea was that this code represents most of the C++ OOP concepts as opposed to doing C programming in C++. On the other hand, we (or at least I) did hope you could read some of the more graphical examples and understand roughly what the code does. These examples are a lot more clear than those in the book where they explain how one theoretical class interacts with another (which is very dry, I can tell you).
haha, but thats fine i understand how oop works now, and ill get an even better idea once i start making the games in the book to see how everything works. but do you think i should have a knowledge as great as the code you typed in before going through this game programming book?
Ehm... I wouldn't expect you to be able to type this code until you finished a CS degree or did a lot of hobbytime programming. Still, being able to read it is a very big plus.
The concepts of OO design:
Every bit of data you have gets its own object.
All objects are of a class, that means, you might have three apples, a pear, a banana and a fruitbox, but they end up being 5 classes even though you get 6 objects. You'd get the general class Fruit (which does not get created, not directly at least), the class Apple, which is a Fruit, and you get 3 apple-objects. Then you have pear, which is a subclass of Fruit, Banana which is another subclass of Fruit, and Fruitbox which is not a fruit, but can contain fruits.
Every bit of data is encapsulated. This seems like pure nonsense at first, why would you make an accessor function for an integer that's right in the class? After a while though, you'll find that that integer needs a new data type, or needs a different handling inside the object. Now you'd be in big trouble with your int accessing functions, but not here. You just make the getX() function use the new method of accessing things.
Objects of the same class (even if the object itself is of a subclass of that class) can all be treated identical, and all functions of that class can be used. The subclass-functions that have the same name automatically get called, so if you want to know how long the pear has until it expires, it doesn't matter whether you call it when you hold it as a fruit, or as a pear, it's got an expiry date, and it's still the same. This is called Polymorphism.
This is the end of the list for me on general C++ concepts.
When you want an object, create it using new. When you want to delete it again, use delete. These functions give you a pointer to the object, that you can use to access it, and pass it around.
When you create an object with new, more happens than meets the eye at first instance. The things that a C programmer would expect is a bit of memory to be gathered. Most C++ programmers see it as a bit of memory being gathered and initialised. In fact, you can customize both the gathering as well as the initialisation. The first is a little out of the ordinary, but for some things (such as an always-present judge, of which there may only be one) it's useful. The second means, that each time you create an object for a class, you can put things in it that you want to put in there. You actually can make a parameter list for all the things you want to know, and then create an object accordingly.
<cut because the forum whined again>