I filled a vector with A objects, then stored these objects address in a multimap [1], but the print message shows that the reference to the object stored in the vector changed [2]. Do you see why? and how avoid any changes.
//[1]
vector<A> vec; 
multimap<const A*, const double > mymultimap;
for (const auto &a : A) {
  double val = a.value();
  vec.push_back(a);
  mymultimap.insert(std::pair<const A*, const double >( &vel.back(), val)); 
  // displaying addresses while storing them    
  cout<<"test1: "<<&vec.back()<<endl;
}
//[2]
// displaying addresses after storing them
for(auto &i : vec)
    cout << "test2: " << &i <<endl;
Results:
test1: 0x7f6a13ab4000  
test1: 0x7f6a140137c8  
test2 :0x7f6a14013000  
test2 :0x7f6a140137c8  
 
     
     
     
    