Boost logo

Boost Users :

Subject: Re: [Boost-users] storing pointers in a std::map
From: Alan Tennant (alan2here_at_[hidden])
Date: 2010-03-11 12:40:57


Value. Like this.

#include <iostream>
#include <map>

void func(int* n)
{
    std::cout<<n<<" "<<*n<<std::endl;
    std::map<std::string, int*> m1;
    //m1["test"] = n;
}

void main()
{
    func(new int());
}

Uncomment the m1... line to uncover the error.

On 11 March 2010 17:25, Rutger ter Borg <rutger_at_[hidden]> wrote:

> Alan Tennant wrote:
>
> > I'm having difficulty storing pointers in a std::map. I can't find
> > anything online about it, are std::maps supposed to be able to store
> > pointers?
>
> Sure, as key or as value? Providing a code example might help in this case.
>
> Regards,
>
> Rutger
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net