C++ Pointers
ok i got a question about pointers. i think i know what they are but i am not sure. ok to me a pointer is a variable that holds the adress for a spot of memory right? and where would that come in handy in game programming. i havnt got to game programming stuff yet becuz i am still learning c++.
The biggest 2 uses for pointers are 1) dynamically allocated memory and 2) referencing other objects.
1) Whenever you need to allocate memory using new or malloc (or some similar function), you'll need to use pointers.
2) Whenever objects need to refer to other objects (such as a room refering to which other rooms it is connected to), pointers are often the most straightforward way to go. They are actually used extensively in general purpose programming for many different data structures, such as linked lists or trees, which you can look up on Google for more info.
1) Whenever you need to allocate memory using new or malloc (or some similar function), you'll need to use pointers.
2) Whenever objects need to refer to other objects (such as a room refering to which other rooms it is connected to), pointers are often the most straightforward way to go. They are actually used extensively in general purpose programming for many different data structures, such as linked lists or trees, which you can look up on Google for more info.
Try creating all the objects in a game on the heap (without using pointers and new). Your answer lies there (plus its just convenient to use pointers sometimes)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement