我的班级有地图作为会员。问题是这个映射的值是boost :: shared_ptr。 当我尝试将一些ement插入map时,发生了一些不友好的编译错误。 这是我的源代码的一部分: 标题:
class Chi2Analyzer: public BaseAlgorithm{
typedef boost::unordered_map<std::string, boost::shared_ptr<TH1D> > HistogramsMap; /* ... */
private:
HistogramsMap h_map;
的.cpp:
Chi2Analyzer::Chi2Analyzer()
{
// initialization of the map
/////////////////////////////////////////////////////////////////
// chi2
std::string histogramName="chi2PerDof";
boost::shared_ptr<TH1D> histogram;
histogram.reset(new TH1D(histogramName.c_str(),histogramName.c_str(), 100,0,1.6e6) );
h_map[histogramName]=histogram;
和g ++输出:
In file included from /usr/include/boost/shared_ptr.hpp:17:0,
from src/../Include/NTupleHandler.h:11,
from src/../Include/BaseAlgorithm.h:5,
from src/../Include/Chi2Analyzer.h:5,
from src/Chi2Analyzer.cpp:2:
/usr/include/boost/smart_ptr/shared_ptr.hpp: In instantiation of ‘boost::shared_ptr< <template-parameter-1-1> >& boost::shared_ptr< <template-parameter-1-1> >::operator=(const boost::shared_ptr< <template-parameter-1-1> >&) [with T = TH1D]’:
src/Chi2Analyzer.cpp:19:22: required from here
/usr/include/boost/smart_ptr/shared_ptr.hpp:305:9: error: use of deleted function ‘boost::shared_ptr<TH1D>::shared_ptr(const boost::shared_ptr<TH1D>&)’
this_type(r).swap(*this);
^
/usr/include/boost/smart_ptr/shared_ptr.hpp:168:25: note: ‘boost::shared_ptr<TH1D>::shared_ptr(const boost::shared_ptr<TH1D>&)’ is implicitly declared as deleted because ‘boost::shared_ptr<TH1D>’ declares a move constructor or move assignment operator
template<class T> class shared_ptr
^
make: *** [Chi2Analyzer.o] Error 1
我该怎么做才能解决这个错误。 最诚挚的问候