The C++ FAQ Lite (
linky) is very good at answering little questions like that, when you have the basic knowledge of C++, rather than none at all.
In response to the
difference between references and pointers:
Use references when you can, and pointers when you have to.
References are usually preferred over pointers whenever you don't need "reseating". This usually means that references are most useful in a class's public interface. References typically appear on the skin of an object, and pointers on the inside.
By "reseating", it means assigning a new object to the reference/pointer. With a pointer to an object, you can change the value of the pointer to a different memory location so that you point to a different object. For example:
Code:
char* pStr = "we love cheeze!";
char* pStrNew = "we hates cheeze!";
pStr = pStrNew;
cout << pStr << endl;
will display "we hates cheeze!" (and you will have a memory leak, but meh).
You can
not do this with a reference, as the reference is a name for an object. You can't separate it from the object. You can, however, write an assignment operator overload for the object, so you can set the object's variables. Eg:
Code:
MyObject x(4,"cheeze!");
MyObject y(10,"bananas!");
x = y;
will make x's variables equal to the variables held in y (persumably, in this example, 10 and "bananas!"). Though this may mean that you are using more memory when working with references (read up on copy constructors and assignment operators, as well as
Resource Acquisition Is Initialization, for some fun times), but means you can avoid memory leaks like the one present in the first example!
Still, there's an argument there about which is better, and depending on who you speak to, you get a different reply
NB: Obviously this is a VERY rough discussion, so don't take it as a know all guide. I don' know everything