c++11 - C++ shared_ptr bind map transform segfault -


i segfault when run code:

#include <memory> #include <algorithm> #include <map> #include <vector> #include <functional>  using namespace std; using namespace std::placeholders;      int main(){   map<int, shared_ptr<int>> container;   container[5] = make_shared<int>(7);    (int = 0; < 10; ++i) {     vector<shared_ptr<int>> vec(container.size());      transform(container.begin(), container.end(), vec.begin(),               bind(&pair<int, shared_ptr<int>>::second, _1));   } } 

i'm compiling g++ 4.8.2 in c++11 mode.

when print use count of shared_ptr, seems gets decremented 1 each time loop runs.

you getting conversions here in bind(&pair<int, shared_ptr<int>>::second, _1)) because pair<int const, shared_ptr<int>> stored in map (note const on key type).

although surprised compiles without error.

try of these:

bind(&pair<int const, shared_ptr<int>>::second, _1)) bind(&map<int, shared_ptr<int>>::value_type::second, _1)) bind(&decltype(container)::value_type::second, _1)) 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -