0

My class has a map as a member. The problem is that the value of this map is a boost::shared_ptr. When I am trying insert some ement into map, some unkind compilation error occurred. here is part of my soure code: header:

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;

and the g++ output:

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

What should I do to fix this errors. Best Regards

user1877600
  • 627
  • 1
  • 9
  • 26
  • 3
    Your version of Boost doesn't quite support c++11 stuff correctly. Upgrade to 1.53 or later. – David Schwartz Apr 28 '14 at 01:34
  • any reason why you are using `boost::shared_ptr` and `boost::unordered_map` and not the `std` versions? – Chris Drew Apr 28 '14 at 01:39
  • If your compiler supports C++11 why don't you use `std::shared_ptr`? – 101010 Apr 28 '14 at 01:40
  • It looks like the copy constructor of `boost::shared_ptr` is marked as deleted for some reason (i.e., `boost::shared_ptr` objects are not meant to be copied). It probably complains about the `h_map[histogramName] = histogram;` because in order for `histogram` to be inserted in `h_map` it has to be copied and consequently the deleted copy constructor of `boost::shared_ptr` has to be evoked. – 101010 Apr 28 '14 at 01:45
  • As @DavidSchwartz mentioned it probably has to do with the version of boost you are using http://stackoverflow.com/questions/11302758/error-while-copy-constructing-boostshared-ptr-using-c11 – 101010 Apr 28 '14 at 01:57
  • It could be the issue with your TH1D class how are you copying TH1D? – praks411 Apr 28 '14 at 10:47
  • possible duplicate of [boost::shared\_ptr::shared\_ptr(const boost::shared\_ptr&)' is implicitly declared as deleted](http://stackoverflow.com/questions/18900730/boostshared-ptrshared-ptrconst-boostshared-ptr-is-implicitly-declared) – Jonathan Wakely Apr 28 '14 at 11:33
  • @DavidSchwartz Thank you! I had installed newest version of boost and this step solve my problems. – user1877600 Apr 30 '14 at 01:01

0 Answers0