Thread: copy constructor causing errors

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    137

    copy constructor causing errors

    i have a class that looks like this

    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;
    };
    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.

    it says:
    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]'
    why is the copy constructor causing errors and how can i fix it. thank you for your help.
    Last edited by yahn; 12-22-2005 at 09:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer conversion problems with a copy constructor
    By stanlvw in forum C++ Programming
    Replies: 8
    Last Post: 01-14-2008, 12:06 AM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Header File Errors...
    By Junior89 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2007, 12:28 AM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM