함수 내에서 unordered_set에 데이터를 저장 한 다음 저장되는 객체에 대한 포인터를 반환하는 경우 함수의 범위 밖에서 포인터가 여전히 유효합니까?기능이 끝나면 std :: unordered_set의 데이터가 삭제됩니까?
예 :
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;
}
다른 기능에서 오류가 발생하여 *intptr
에 액세스하려고합니까? 또는 unordered_set의 범위가 끝날 때 unordered_set의 데이터가 할당 해제됩니까?
http://stackoverflow.com/questions/6441218/can-a-local-variables-memory-be-accessed-outside-its-scope – chris