开发者

C++ map.clear() pure virtual method runtime error

开发者 https://www.devze.com 2023-03-24 05:18 出处:网络
I believe the problem may stem 开发者_开发问答from using boost::shared_ptrs as key values. //header file:

I believe the problem may stem 开发者_开发问答from using boost::shared_ptrs as key values.

//header file:
#include <map>
std::map<boost::shared_ptr<foo>, bar> myMap; // Private member variable

//////////
myMap.insert(pair);
//////////
myMap.clear()

Neither foo nor bar are abstract classes. At which point, during run-time, I will receive a "pure virtual method called" error, and my program will terminate. I've also tried iterating through the map and using myMap.erase(iterator), which produces the same error.


If bar is a polymorphic type, when you it could be slicing the class. Depending on what the destructor is doing, it could then access a pure virtual method.

0

精彩评论

暂无评论...
验证码 换一张
取 消