Ptr_map insert

I have a predefined type that inherits boost :: noncopyable (so I have to store a pointer to these objects). I am using boost :: ptr_map . As I know, the second argument in it is already a pointer. So the code:

ptr_map<string, boost::any> SomeMap;
typedef %Some noncopyable class/signature% NewType;

// Inserting now
boost::any *temp = new boost::any(new KeyEvent());
SomeMap.insert("SomeKey", temp);

Error:

error: no matching function for call to β€˜boost::ptr_map<std::basic_string<char>, boost::any>::insert(const char [11], boost::any*&)’


UPD . When I do not pass a pointer to anyany temp = any(new KeyEvent());

I get:

error: no matching function for call to β€˜boost::ptr_map<std::basic_string<char>, boost::any>::insert(const char [11], boost::any&)’

+3
source share
1 answer

insert -const-, , . ; temp , .

:

string key("SomeKey");
any* temp = new whatever;
SomeMap.insert(key, temp);

auto_ptr, , , :

auto_ptr<any> temp(new whatever);
SomeMap.insert("SomeKey", temp);
+6

Source: https://habr.com/ru/post/1750710/


All Articles