I think my understanding of references is incomplete. I would like to create a vector of references to a type, the purpose being to gain the benefits of a vector without having to copy each element or use pointers. Why is it not possible to create a vector of references? (I tried with Borland 5.5.1 on Win32 and got a slew of errors referring to "Cannot define a pointer or reference to a reference in int main()").
My code:
Code:
#include <iostream>
#include <vector>
using namespace std;
class MyTest {
public:
MyTest() {
cout << "Creating a new MyTest object!" << endl;
}
MyTest( const MyTest& ) {
cout << "Creating a new MyTest object!" << endl;
}
};
int main() {
MyTest a;
MyTest b;
vector< MyTest& > baz;
baz.push_back( a );
baz.push_back( b );
}