Dealing with C++ Syntax Errors ------------------------------ A compiler error message will list a file and line within that file. That's where the compiler became convinced that something was wrong. Sometimes you can understand what the message says is wrong, and sometimes you can't. Sometimes the problem is where the compiler noticed the problem, and sometimes it's somewhere before that, sometimes much before that. Finally, one thing wrong in your code can lead to many, many error messages. All of that leads to the following recommendation: try to fix whatever is causing the first error message, and then recompile (at least until you become a very experienced C++ programmer). Repeat. references ---------- C++ has real references. A reference is an alias - another name for something: int x = 10; int &xRef = x; The '&' in the declaration means "reference to," so xRef is a reference to an int. It's initialized to be an alias for x. So, after that definition, the statement xRef = 6 has meaning identical to x = 6. A main use for references is to implement call-by-reference: void swap(int &x, int &y) { int tmp = x; x = y; y = tmp; } Now if the caller says: a = 1; b = 2; swap(a,b); on return a will equal 2 and b will equal 1. Note that this is still call by value. The parameter variables, x and y, are initialized by the value of arguments, a and b. Since the parameters are references, they become aliases for the arguments. While executing the swap() code for this call, 'x' means the variable 'a' (but note that 'a' is out of scope, and so that name could not be used), and 'y' means 'b'. The implementation of references is not defined by the language -- the compiler can do anything it wants, so long as what it does has the right effect. While it's tempting to think of references as pointers, they are not. Pointers take up space. References don't: char c = ' '; // sizeof(c) == 1 int * pInt; // sizeof(pInt) == 8 char &refChar = c; // sizeof(refChar) == 1 Finally, C++ does not provide any way to refer to a reference, once it has been declared. So: int &ref; // is an error - you must initialize a reference ref = y; // sets the variable that ref refers to to the value of y. C++ const keyword ----------------- Note: const is an aid to the programmer, it is not a security feature. Like in C, the const keyword indicates that you'd like the compiler to raise a compile time error if the code tries to change the value of something. Example: const int x = 10; Any attempt to assign any value to x (even 10) will be an error, for example: x = 8; // compile time error That also means that this is an error: const int y; since there'd be no way to ever assign a value to it. For reasons that will be clear in a second, you can say int const x = 10; and it means exactly the same thing as const int x = 10; Varible declarations can include many type modifiers. As simple example: int * pInt = &x; Now there are two different things you might want to const: - pInt, meaning that you couldn't assign to it again (it will always point at x), or - *pInt, the value it points at That means you can insert up to two 'const' keywords in that declaration: const int * const pInt = &x; That's a pointer to x that cannot be made to point to anything else and cannot be used to modify the value of x. To understand a complicated declaration with consts in it, read from right to left: int const * const * pIntStar = &pInt; Read that as "pIntStar is a (variable) pointer to a const pointer to a const int." That is, you can change the value of pIntStar (point it at something new), but you can assign to *pIntStar not to *(*pIntStar)