c++ - error: no matching function for call to default copy constructor? -


i have std::map container variable in class populated objects of nested-class:

class logger { private: //...     class tick{         ///stores start , end of profiling         uint32_t start, lasttick,total;         /// used total time         boost::mutex mutextotaltime;         ///is profiling object started profiling?         bool started;     public:         tick(){             begin();         }         /*         tick(const tick &t){             start = t.start;             lasttick = t.lasttick;             total = t.total;             started = t.started;         }         */         uint32_t begin();         uint32_t end();         uint32_t tick(bool addtototaltime = false);         uint32_t addup(uint32_t value);         uint32_t getaddup();      };     std::map<const std::string, tick> profilers_; //... public: //... logger::tick & logger::getprofiler(const std::string id) {     std::map<const std::string, tick>::iterator it(profilers_.find(id));     if(it != profilers_.end())     {         return it->second;     }     else     {         profilers_.insert(std::pair<const std::string, tick>(id, tick()));         = profilers_.find(id);     }     return it->second; } //... }; 

the above code not compile if dont provide copy constructor while thought default copy constructor should in place?! missing concept? thanks

the copy constructor may generated if members of class copyable. in case of tick have object

boost::mutex mutextotaltime; 

which not copyable, compiler not generate copy constructor. observe in commented out copy constructor not copy mutex - because know should not. compiler not know that.

as side note, there no need explicitly const map keys:

std::map<const std::string, tick> profilers_; 

map keys const, , declaration equivalent to

std::map<std::string, tick> profilers_; 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -