   Can someone explain to me what pointers could be used for in game devlpoing?
  The title says it all. By the way if anyone can tell me the point of using classes in game developing and its benefits that would be great   
  Seems to me that you don't understand what a pointer actually does. ;)PointerssearchOOP;  To be a little helpful, pointers and classes are good...and honestly necessary for ANY kind of development, games included.  You are going to find yourself in several situations where it isn't safe to access certain memory addresses, so you will find yourself using either a pointer or a reference.  You will also find a lot of use of pointers when working through vectors using iterators.  It's kind of a hard question to ask, considering the high amount of uses for pointers and references.As for classes, they are almost the whole reason to be an object oriented programming language.  You use classes to make your functions and variables more modular, and encapsulate your object.I'm pretty sure my explanations are horrible, as it is 1:41AM here and I'm only surviving off of dark chocolate right now...but that was the best my mind could muster at the moment.  Those are rather difficult questions to answer short-hand.   ;  on the pointer side of things i'll try an analogy...imagine you have a wall to graffiti on.  you can paint whatever you like and can paint over what was there before.  the wall is sectioned off into equal sized areas to paint on.  now imagine if to claim a section of the wall to paint on you first had to have a separate spray can for each section you wanted to paint on, and depending on the brand of the spray can determined how many sections you got to paint on but also with the restriction that you HAD to paint on the number of sections you claimed with that can e.g. one brand only lets you paint on one section, another brand lets you paint on four sections but each time you paint you MUST paint into each of those four sections.now with that setup and an almost unlimited supply of various brands of spray paint you can do a whole lot of painting and do some pretty cool designs.but what if someone said to you "hey, here's a magic spray can and a skateboard... with the skateboard you can zoom to any area of the wall and with this magic spray can you can write on any part of the wall you like and there is no restriction on how many sections you have to write on in one go"with this magic spray can and the skateboard you can move to a section and write anything you like on it, then skate around and then write on one section, then skip a section, then write on the next 2 sections, then skip 100 sections, then write on 30 sections, then skip another, then write on 2 sections... WHATEVER.the problem though, as is with any type of freedom in life, is that once you have been given the freedom to do what you like you then have responsibilities to use that freedom in a way that doesn't impact on others.  So even though you can now write whatever you like anywhere you want on the wall, you have to be aware that you aren't the only person using the wall and so shouldn't paint over someone elses section that they have claimed already otherwise you are almost guaranteed to start a fight.now replace 'the wall' with 'application memory'- 'painting on the wall' with 'writing to memory'- 'the wall is made of equal sized sections' with 'memory is made up of bytes'- 'different brands of spray paint' with 'different variable types'- 'to use a specific type of spray paint means you HAVE to write on the amount of sections the brand determines' with 'depending on which type of variable you use determines on how many bytes you are writing to'- 'magic spray can and a skateboard' with 'a pointer're-read what i just said and it might make some kind of sense.coming from a Delphi programmers perspective the following may not mean anything to most people... if you have used Arrays before and didn't already realise it then you should be aware now that an array is really a type of pointer implementation.  i think in C the equivalent is a Vector or something, but don't quote me.if you needed 80 lots of 4 sections you would need to have 80 different DWORD variables and specifically use each one separately... or the only actually usable way is you can claim 80 DWORDS of memory and then access whatever group of 4 bytes you want using just one pointer of type DWORD... or just have an array of 80 DWORDS.ok i can see it in my head but maybe not explain it properly.now onto the 'class' part of the question.  a class is a bit like a car or a bike or a duck or a ........WHATEVER you need it to be.  if in your program you wanted to store information about a whole bunch of cars you would simply need to declare the different parts that make up a car and call it 'MyCar', and then once you've done this you can then make a variable called Car1 of type MyCar.in doing this you have grouped a whole load of different properties together into one cohesive unit that you have described as MyCar, and have declared a variable that now represents that entire group of properties.  now the real use of this is NOT for representing just one MyCar, as to do so you could just list the different variables individually.  the REAL use of classes is that it now gives you the ability to declare as many MyCar's as you now like, and following from the 'array' point i made above you can declare an array of MyCars and therefore in one simple line of code you can change it from being just 5 cars to 10000000 cars all each containing the properties that make up a MyCar type.building from this you can then declare MyBike and say what makes up a MyBike.  You do this because you need something somewhat different from a MyCar.  Something with maybe a similar set of properties but not quite the same.then you can make a MyBoat.then you think to yourself... "Oh my god... SELF!  WAKE UP!  Self I just realised something.  I can now declare a type called 'MyVehicles' and withing that type I can declare an array of MyCars and MyBikes and MyBoats and in doing so I have conveniently grouped them all together under one large umbrella.  OH WOW if i REALLY wanted to I could then have a MyCity type and within that type have a MyVehicles type which then has the different MyCars and MyBikes and MyBoats within that City... and they would all be grouped together under the one umbrella of MyCity, and also with that I could then create other things that can come under MyCity such as MyPeople types and MyStreet types etc etc"classes are all about grouping things together into one big bundle of fun.  once you have done this you can then move that whole bundle of fun around so easily and make copies of them in one foul swoop etc etc and so on.  Many many uses.  it all depends what how you implement it and what you are trying to achieve.Any time you speak you are in a way using the equivalent of a 'class'.  If you talk about water then the word water has meaning separate from the word air etc.  in the MyWater class you would have an array containing 2 hydrogens and 1 oxygen, and how much water you have depends on the size of the array you have defined.  you could have one molecule of water in which case the array would be of size 1, or you could have a million molecules of water in which case you would have an array of size 1 million.hopefully that makes some sense.   ;  Thats a pretty good explanation nb thank you. I understand classes now but pointers I'm a little iffy   ;  What sounds better/faster/easier to you: Knowing where (pointer) you put your elephant (allocated memory), or moving it around and/or cloning it every time you need it somewhere else? (very general)- Pointers can be put into lists and other data structures, that you can then sort, search, etc, without having to move/make copies of potentially large blocks of memory.- Pointers allow you to modify the value of a parameter passed into a function. Consider that you want to write a function to swap two parameters.These are just a few of the uses for pointers.   ;Quote:Original post by Dragon_LanceThats a pretty good explanation nb thank you. I understand classes now but pointers I'm a little iffyWhen you pass an object by value to a function, two things happen: 1) The entire object is copied into a new local variable. For large objects, this can be expensive.2) Because you're dealing with a copy of an object, you lose the ability to modify or refer to the original object.Say you have in your game an event manager object whose job is to call the handleEvent() method of objects who have subscribed to listen for particular events. The event manager has to keep a registry of subscribed objects so it can call them properly when events come in. Say subscribers register with the manager by calling a member function named register().There's two options - register(EventSubscriber subscriber) and register(EventSubscriber* pSubscriber). Consider the first option. If subscribers send their information by value, the manager gets a copy of the subscriber for its registry. When the manager calls the handleEvent() method of the objects in its registry, these calls will get sent to copies of EventSubscribers, not the original EventSubscribers that registered for the event. This isn't what we want.If you pass a pointer to an EventSubscriber to the register() function, these problems go away. First, you're not copying an entire EventSubscriber every time one registers. Second, the event manager's registry will hold pointers that point to the correct EventSubscribers. When the manager calls the handleEvent() methods of its subscribers, it will be calling the correct objects. Generally speaking, these are the reasons we use pointers. They allow us to skip unnecessary copying, and they allow us to pass actual objects around instead of just copies.   ;Quote:Original post by Dragon_LanceThe title says it all. By the way if anyone can tell me the point of using classes in game developing and its benefits that would be greatClasses in general will save a ton of time for you.  It allows you to reuse code without having to type everything all over again.  For example, if I made a class called Monster that has the standard size for monsters in the game, bounding box collision, and stats.  I can reuse that class for my Goblin, Orc, and Troll monsters by using that class.For example:You have your Monster class done, and to use it you just do this:Monster Goblin();Monster Orc();Monster Troll();Each holds all the data in your class, for example:Goblin.Show_Health();The .Show_Health(); part can be used with Orc, and Troll.  Which allows you to reuse your code and save a lot of time, not to mention it just looks cleaner.The sooner you get into the habit of using classes in game programming, the more you will appreciate such a feature.  :)   ;Quote:Original post by MrCpawMonster Goblin();Monster Orc();Monster Troll();Are you sure you want to declare three functions taking no arguments and returning Monster? :)   ;  Classes are all about packaging data into a single entity, much like (in C++, exactly like) a struct, along with the functions that can operate on that data. Classes also go one further and introduce the idea of hiding some data from the outside world. In the old days, all we had were structs, and all the data was open for everyone to see. To operate on that data we created functions that took in these structs as parameters, but these functions were separate entities than the data they operated on.Here's a scenario where this all comes together -- Imagine you were making a class to represent a string of text. What we want to do is be able to get and set the string, as well as getting its length, among other things. Because we know that the length of the string can only change when the contents of the string change, we want to recalculate the length only when the string is changed, and hang onto it so we can pass it out when the user requests it.In C, we'd have to do something like this:struct SString {  char * String;  int    Length;};void ConstructString(SString *this, const char * string){  SetString(this, string);}void DestructString(SString *this){  if(this->String)    free(this->String);}void SetString(SString *this, const char * string){  if(this->length != strlen(string))  {    if(this->String) free(this->String);    this->String = malloc(strlen(string) + 1);  }  strcpy(this->String, string);  this->Length = strlen(this->String);}const char * GetString(SString *this){  return this->String;}int GetLength(SString * this){  return this->Length;}There are a few not-so-nice things about this. First, these functions are all separate from each other and the data they operate on -- it would be nice if things were all packaged together so that we could think of strings as a logical unit. Its slightly akward to think about on a conceptual level, but at least it doesn't really harm us. Next up is something more harmful, structs don't allow us to hide data from the outside world -- even though we made these nice functions that we want the user to use, nothing stops them from accessing the data directly, and they might inadvertently change the length like so:(if MyString.Length = 10) { /* do something */ } // Yes, '=', not '==' -- thats the mistake :)They might also change the string directly, but forget to update the length, and this would be bad because we might later call GetLength on a string that contains "cat", but will report a length of 20 -- bad information is sure to lead to bad decisions, and bad decisions tend to lead to CrashVille.They might also forget to call DestructString, which would lead to memory leaks.in C++, using a proper class, we might do something like this:class CString{public:  CString(char * string); // in proper C++, you'd use the std::string class, but we're just demonstrating.  ~CString();  void SetString(const char * string);    const char* GetString() const;  int    GetLength() const;private:  char * String;  int    Length;}CString::CString(SString *this, const char * string){  SetString(this, string);}CString::~CString(SString *this){  if(this->String)    free(this->String);}void CString::SetString(const char * string){  if(this->length != strlen(string))  {    if(this->String) free(this->String);    this->String = malloc(strlen(string) + 1);  }  strcpy(this->String, string);  this->Length = strlen(this->String);}const char * CString::GetString(){  return this->String;}int CString::GetLength(){  return this->Length;}As you can see, each function is now a part of the CString class, in C++ we call these "member functions" but they are also sometimes referred to as "methods".You can also see that we've hidden the variables that are part of our CString class, in C++ we call these "member variables" but they are sometimes refered to simply as "members". Now our users cannot gain access to these variables themselves -- they must go through the member functions we've provided -- and this makes it much harder for them to make silly mistakes.The set of publicly available member functions we've provided is known collectively as the "Interface" of the class. We can also make functions that are private to hide them from the user of our class, that will only be available to other member functions of the same class -- for instance, if C did not provide a strlen() function already, we could make it a private member function of our CString class because we use it many times internally, but we want our users to use the Length() function we've provided them.These are only the more basic benefits that classes provide. I won't go into detail because I don't think you're to the point in your abilities that it really matters just yet, but classes also support inheritance, and make things like polymorphism and creating constant instances easy (these are possible in C with plain structs, but are brittle, ugly and more restricted. These are other very important features of classes which you will surely find indispensable in your future.Pointers are a different horse entirely, though they are often used with classes or structs. A pointer is a variable which holds the address of some other piece of data -- maybe a class, maybe an integer, whatever the case may be. If you pass an parameter to a function via a pointer, you have the actuall address of the data you passed in, and can therefore change the data, whereas if a parameter is passed by value a copy is made, and any changes you make to that copy will be lost once you exit that function. Next up, pointers and arrays are closely related -- if you have a pointer to the first element in an array, and you increment or add 1 to that pointer, it will then point to the second element in the array. This is a powerful feature of pointers called "pointer arithmetic" -- given a pointer into an array, you can "walk" the array backwards or forwards, possibly several steps at a time, with simple mathematical expressions -- often more efficiently than manipulating and applying an index to access elements of that array -- you just have to be sure you don't walk youself clear out of the array with your mathematical expressions, of you're sure to crash. Another useful features of pointers is that you can set a pointer to zero to signify that it doesn't point to anything useful. Finally, pointers can be "reseated" -- that is, they can be made to point to another piece of data entirely, so long it what it's pointing at is the same type.Related to pointers is something called a "reference" in C++. These are like pointers in that they also supply an address to some piece of data, allowing it to be changed, but are unlike pointers in that they do not support pointer arithmetic, and cannot be reseated -- as a consequence of this, references must be constructed to take the address of an existing variable and can never point to zero like a pointer can (because if you can never change what it points to, it better point to something useful).   