我调用以下代码(调试错误与第二行有关):
boost::shared_ptr<EX> e(new LE());
F* f = new F("", e, 2);
我在access violation reading location
库中收到调试错误(boost::shared_ptr<>
):
void add_ref_copy()
{
// ERROR HAPPENS HERE!!!!!!!
BOOST_INTERLOCKED_INCREMENT( &use_count_ );
}
这是上述电话中涉及的代码(如果您需要查看更多代码,请与我们联系)。
问题显示当我单步进入F
的构造函数时,我会立即“跳过”构造函数签名行。
编辑这就是调用堆栈的样子:
boost::detail::sp_counted_base::add_ref_copy() Line 74 C++
boost::detail::shared_count::shared_count(const boost::detail::shared_count & r) Line 383 C++
boost::shared_ptr<OB>::shared_ptr(const boost::shared_ptr<OB> & r) Line 397 C++
std::std::(boost::shared_ptr<EX> * e) Line 4 C++
boost::boost::(std::unordered_map<std::string, boost::shared_ptr<I>, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<const std::string, boost::shared_ptr<I> > > > *) Line 261 C++
F.cpp
//When the debugger is on this line, stepping over once more causes the error
F::F(boost::shared_ptr<EX> ex) : DV(ob)
{
//Debugger never reaches this line
ob = EX->getX();
}
F.h
#include "D.h"
#include <boost\shared_ptr.hpp>
class F: public D{
public:
F(boost::shared_ptr<EX> e);
virtual ~F();
F(const F& f);
F& operator=(const F& f);
private:
};
DV.cpp
DV::DV(boost::shared_ptr<OB> ob) : I(ob)
{
}
DV::~DV()
{
}
实施例H
#include "OB.h"
#include <boost\shared_ptr.hpp>
#include <unordered_map>
class EX{
public:
EX();
EX(const EX& src);
virtual boost::shared_ptr<OB> getX() = 0;
private:
};
EX.cpp
EX::EX(){
}
EX::EX(const EX& src){
}
LE.h
#include "EX.h"
#include "OBO.h"
#include <boost\shared_ptr.hpp>
#include <unordered_map>
class LE : public EX{
public:
LE();
LE(const LE& src);
virtual boost::shared_ptr<OB> getX();
private:
};
LE.cpp
LE::LE(){
}
LE::LE(const LE& src){
}
boost::shared_ptr<OB> LE::getX(){
return boost::shared_ptr<OB>(new OBO);
}