typedef struct MyStruct {
unordered_set<int> mySet;
}MyStruct;
int main(){
unordered_set<int> sset{ 1,2,3,4,5 };
MyStruct tk;
tk.mySet = sset; //This works fine.
for (auto x : tk.mySet) printf("%d ", x);
MyStruct *Arr = (MyStruct *)malloc(10* sizeof(MyStruct));
Arr[0] = tk; // This isnt working, giving an exception
//the same code runs as expected on codeblocks
for (auto x : Arr[0].mySet) printf("%d ", x);
return 0;
}
This is the exception i get when i run the debugger.
.exe!std::list
::_Orphan_ptr(std::_List_node * _Ptr) Line 1919 C++ .exe!std::list >::clear() Line 1501 C++
.exe!std::_Hash,std::equal_to >,std::allocator,0> >::_Copy(const std::_Hash,std::equal_to >,std::allocator,0> > & _Right) Line 843 C++
.exe!std::_Hash,std::equal_to >,std::allocator,0> >::operator=(const
std::_Hash,std::equal_to >,std::allocator,0> > & _Right) Line 291 C++
.exe!std::unordered_set,std::equal_to,std::allocator >::operator=(const std::unordered_set,std::equal_to,std::allocator > & _Right) Line 187 C++
.exe!main()
[External Code]
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
Aucun commentaire:
Enregistrer un commentaire