how to release element from ptr_map?
I have an instance of ptr_map
archie14 skrev:
I have an instance of ptr_map
. I need to release an element from the map and use it somewhere else, making sure that it will not be deleted when the instance of ptr_map is deleted. I am successfully doing it with ptr_vectors, but can't get it right with ptr_map. What is the proper syntax of such call?
I am doing it like in the code below, which does not compile.
class classA {};
typedef ptr_map
ptrmaptype; ptrmaptype val; val.insert(1, new classA());
ptrmaptype::mapped_type t = val.release (val.begin()); // I want "t" to be of classA* type
Does ptrmaptype::auto_type ptr = val.release(val.begin()); not work?? Then you can call ptr.release() to get the naked ptr. HTH -Thorsten
Thorsten Ottosen
archie14 skrev:
I have an instance of ptr_map
. I need to release an element
from the map and use it somewhere else...
Does
ptrmaptype::auto_type ptr = val.release(val.begin());
not work??
Then you can call ptr.release() to get the naked ptr.
HTH
-Thorsten
Yes, it works, thanks for the help. I think that I started with auto_type, got compile error and moved to try other types. Now it works. Thanks again.
participants (2)
-
archie14
-
Thorsten Ottosen