If, inside a function, I store data in an unordered_set, and then return pointers to the objects being stored, will the pointers still be valid outside of the scope of the function?
eg.
int *myFunc(){
std::unordered_set<int> hashset;
//add some objects
hashset.insert(4);
hashset.insert(5);
hashset.insert(6);
int *intptr = &(*hashset.insert(4)); //try to insert an object that may already be in the set, and get a pointer to the object in the set
return intptr;
}
will trying to access *intptr
in another function cause an error? Or is the data in an unordered_set deallocated when the scope of an unordered_set ends?