我对C ++还是很陌生,遇到了一个问题,我似乎无法在地图上插入新的派生类。
我的代码简化如下:
std::map<int, std::unique_ptr<Base_Class> > m;
void func(){
for(int num = 0; num < 100; n++){
m.emplace(num, new Derived_Class() );
}
}
哪个给我这个:
error: no matching function for call to 'std::pair <const int, std::unique_ptr<Base_Class> >::pair(int&, Derived_Class*)
我尝试使用以下方法失败:
m.emplace(std::pair(num, new Derived_Class()) );
这给了我这个:
error: no matching function for call to 'std::pair<const int, std::unique_ptr<Base_Class> >::pair(std::pair<int, Derived_Class*>)
我似乎无法弄清楚这一点,将不胜感激。