i have a class that looks like this
when i leave the comment in i can compile the program with no problem. when i take it out, it doesn't increment the instanceCount when it is coppied, which i need it to do. i get an error when i try to initilize a vector of type player.Code:class player { public: player(string name = "", int si = 0):_name(name){_spriteIndex = si; instanceCount++; cout << endl << "constructor of " << this->_name << ":: there are " << instanceCount << " players" << endl;} ~player(){instanceCount--; cout << endl << "destructor of " << this->_name << ":: there are " << instanceCount << " players" << endl;} //player(player &rhs){_name = rhs.get_name(); _spriteIndex = rhs.get_spriteIndex(); instanceCount++; cout << "copy constructor:: there are " << instanceCount << " players" << endl;} string get_name() const {return (_name);} void set_name(string name){_name = name;} int get_spriteIndex() const {return (_spriteIndex);} void set_spriteIndex(int si){_spriteIndex = si;} static int get_instanceCount() {return (instanceCount);} private: string _name; int _spriteIndex; static int instanceCount; };
it says:why is the copy constructor causing errors and how can i fix it. thank you for your help.Code:in concstructor 'std::vector<_Tp,_Alloc>::vector(size_t)[with_Tp = player,_Alloc = std::allocator<player>]' line 50 : vector<player> players(0); instantiated from here no matching function for call to 'player::player(player)' candidates are player::player(plyaer&) player::player(std::string, int) in function 'void std::_Construct(_T1*,const_T2&)[with _T1 = player,_T2 = player]'



LinkBack URL
About LinkBacks



