Originally posted by: brandonb
I'd just like to add: this is one example of using a C++ pointer that you cannot do in another language like .NET...
Lets say you have structure:
struct myStruct
{
char Name[50];
int Lvl;
int HitPoints;
int SwordSkill;
};
myStruct *Pointer = new myStruct[5]; // The data type doesn't mean anything, a pointer is a pointer, the only thing it does is make it so if you do math to the pointer, like Pointer++ it advances the pointer to the next part in memory of that type. So adding 1 to that actually advances 62 memory spots because that struct is 62 bytes big.
Now load up a saved game file. All kinds of crap in a byte stream.
memcpy(Pointer, sizeof(myStruct) * 5);
It loads directly from the file (which is just an array of bytes) directly into the structures. And it works just fine. In any other language, you have to copy each individual element from the file to the structure, since they don't allow pointers to do things in bulk. Pointers are much faster. That gives you the power of a pointer, and why games are made in C++.