Sign in to follow this  
lordcorm

Long question post!?

Recommended Posts

Ok here are some questions i have after i read the "Beginning C++ Game Programming". First, is pointer i dont undertand at all!! :(:( Second, How do referances work? third, how whould i make it so when i have a class named "goblin" and his health reachs zone that it moves on to the next thang in the main function? fourth, if you have this book i didnt get the chapter 9 "Advanced Classes and Dynamic Memory" any comments on that? Fivth, Now that im done with that book would any of you guys that have this book suggest it for a person that has just been done reading my book? The book is "Game Programming in C++: Start to finish, do you suggest any books before i read that one or am i a ok to start? If you guys could anserw thoughs questions i would realy realy appreasiate it!

Share this post


Link to post
Share on other sites
I suggest you reread the whole book a few times before you do anything else. If you don't understand something, read over that section again until you do.

Remember to try out the examples, and not just copy&paste them. Type them yourself, and compile them yourself to see how it works. Change a few things and see what affects what, and what means what.

Do all the exercises and questions. Don't just skimp over them. Once you do, make sure that the results you get are what you're supposed to get.

Share this post


Link to post
Share on other sites
Your questions are rather broad and there exist many resources on-line which can answer them more comprehensively than we can -- just do a Google search. If you have specific questions, perhaps about a section of code you wrote, then we can be a much better resource for answering those.

Regarding which book to get next, what programs have you written so far using your current C++ knowledge? Have you written a number guessing game? Have you tried writing a simple text adventure? It seems that you may want to continue rereading the book you have since you have so many questions, supplementing it with projects that you come up with to help you better understand the book's text. Once you get a good handle of C++, then you'll have a clearer idea of what kind of book you will be able to understand next.

Share this post


Link to post
Share on other sites
You are aware by now, I hope, that you can have a variable of a specific type in a C++ program, for example:

int x;

You could also declare a pointer to an int like this:

int *p;

p is a variable that contains the address of another variable. At the moment, p does not have an address assigned to it. We can make it point at x like this:

int x;
int *p=&x;

The '&' in front of the x means "get the address of". p is now "pointing" at x. If we were to do this:

int x=123;
int *p=&x;

cout << p << endl;

the result would be that the address of x would be printed. If, however, we did this:

cout << *p << endl;

then '123' would be printed since the * in front of the p means "get the value that the pointer is pointing at".

References work like this:

int x;
int &r=x;

r is now an alias for x, but is used just like x and cannot be reassigned. These are of most use in functions:

void f(int x)
{
x=10;
}

void g()
{
int a=100; f(a); cout << a << endl;
}

After running f() in g(), the value of a is still 100 because by default, a copy of a variable is passed to a function, not the actual variable itself. If, however, we were to change this to:

void f(int &x)
{
x=10;
}

void g()
{
int a=100; f(a); cout << a << endl;
}

Then after f(), a would equal 10 since, by using the &, we have declared the the parameter is a reference. This means that any changes to the parameter in f will also affect the variable that is passed into the function.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this