问题
Possible Duplicate:
Why use pointers?
I know what the C++ & does. but what can it be used for?
回答1:
&is used to pass address of arguments (pointer) to function, when it's used at calling site.&is used to pass arguments by reference to function, when it's used in function parameter list.&is bitwiseAND. e.g.(a & b)&is used in logicalAND. In this case, two&make logicalAND. e.g(a && b).
回答2:
For example to pass a pointer to your object into some function.
回答3:
Many functions in the STL or other commonly available libraries requires a pointer to an object (not the object itself). Also, many time you'll want to pass pointers. When you need that, the & operator allows you to get a pointer to any object you have access to.
Browse through the boost libraries and find some. One example:
template<class Y> explicit shared_ptr(Y * p);
To pass in a pointer to a Y you'd have to use the & operator.
Furthermore, your profile says you're into 3-d games. Almost every C++ 3d library I know of uses pointers to arrays of floats or ints to manipulate everything. You need the & operator to pass in the pointers to those arrays.
来源:https://stackoverflow.com/questions/5051894/c-address-operator-uses