PDA

View Full Version : Delete auto pointer from QMultiMap



phillip_Qt
3rd December 2007, 09:41
HI all
My problem is that in side QMultiMAp i ve passed auto ionter like below.

QMultiMap<qint32, IAutoPtr>::iterator iter = NULL;

while im trying to delete the IAutoPtr like

delete iter.value(); its showing error "argument given to `delete', expected pointer"

IautoPtr is an auto pointer.

Can any body help me?

Thank you all.

jacek
3rd December 2007, 10:15
Which auto pointer class do you use? Is it std::auto_ptr?

phillip_Qt
3rd December 2007, 12:51
Which auto pointer class do you use? Is it std::auto_ptr?

ya its std::auto_ptr

jpn
3rd December 2007, 14:09
ya its std::auto_ptr

auto_ptr inside container classes (http://gcc.gnu.org/onlinedocs/libstdc++/20_util/howto.html#2):

Never ever use a container of auto_ptr objects. The standard says that "undefined" behavior is the result, but it is guaranteed to be messy.

wysota
3rd December 2007, 17:08
What is the reason of using an auto pointer in the map?

DeepDiver
3rd December 2007, 18:29
Something similar has already been discussed:
http://www.qtcentre.org/forum/f-qt-programming-2/t-qmap-10352.html

Look here:
http://www.boost.org/libs/smart_ptr/smart_ptr.htm