The question comes from the code below:
vector<int &> one; //compile failed
I am confused why the code does not compile.
The question comes from the code below:
vector<int &> one; //compile failed
I am confused why the code does not compile.
You can't have a vector of references directly.
However you can use std::reference_wrapper
to achieve the result you seek.
Possible duplicate of Why can't I make a vector of references? (I don't currently have the rep to flag it).
STL containers must hold types that are assignable, and references are not assignable.