"Andy" <gn***@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi,
Could you explain why vectora<int&> is not allowed?
Because vector (and other containers) can only store
objects, and a reference is not an object. It's simply
an alternative name for an existing object. Containers
store objects, not names.
For example, the following prgram will be given compilation error.
And rightly so.
#include <vector>
using namespace std;
int main()
{
vector<int&> myvec;
return 0;
}
BTW why do you feel the need to try to store a
collection of references? You can (and often
should) use a reference to a container, e.g.
as a function parameter, which eliminates the
need for a copy operation when the function is called
(C++ passes function arguments by value by default).
-Mike