0

我相信问题可能源于使用 boost::shared_ptrs 作为键值。

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

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

foo 和 bar 都不是抽象类。此时,在运行时,我将收到“调用纯虚拟方法”错误,我的程序将终止。我也尝试过遍历地图并使用 myMap.erase(iterator),这会产生相同的错误。

4

1 回答 1

1

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.

于 2011-07-30T20:26:00.513 回答