开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜