| Author | 
		Message | 
	
		 
		zero-impact
 
  
 
    
		 | 
		
		
			
				  Posted: Fri Oct 02, 2009 8:41 pm    Post subject: Help with solitaire game  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				OK so I am working on a project for my gr.12 cs class. The first part of the project is making a solitaire game playable by people.
 
 
My problem is that my program is crashing for no apparent reason.
 
 
	  | c++: | 	 		  #include <vector>
 
#include <iostream>
 
 
#include "card.h"
 
 
using namespace std;
 
 
class Mouse {
 
public :
 
    int x, y;
 
 
    void add_card (Card *card);
 
 
    bool down, down_last;
 
    bool clicked();
 
 
 
protected :
 
    vector <Card *> cards;
 
};
 
 
 
void Mouse::add_card(Card *card) {
 
 
 
    cards.push_back(card);         //This is where it crashes!
 
 
 
}
 
 
bool Mouse::clicked() {
 
    return down && !down_last; //If the mouse is pressed down but wasnt pressed down the last time it was updated
 
}
 
  | 	  
 
 
I have double checked that it is passing a valid pointer to the function. It just seems that the vector "cards" is not accepting anything. Also if I output cards.size() before push_back is called even once it outputs 8. I can supply more details upon request.
 
 
Any help is appreciated  
 
 
 
Edit: This class represents the users mouse. The vector 'cards' holds the cards that the user is currently dragging from one stack to another. | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	
	 
		  | 
	
				 
		DtY
 
  
 
    
		 | 
		
		
			
				  Posted: Fri Oct 02, 2009 9:06 pm    Post subject: RE:Help with solitaire game  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Don't you have to do something to initialize a vector? (Or is that done automatically in c++?) | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		zero-impact
 
  
 
    
		 | 
		
		
			
				  Posted: Fri Oct 02, 2009 9:53 pm    Post subject: RE:Help with solitaire game  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| When I call cards.push_back(), it should dynamically allocate memory as far as I'm aware. I have a nearly identical set up for the other classes that contain a vector or stack of pointers to Card objects. | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		saltpro15
 
  
 
    
		 | 
		
		
			
				  Posted: Fri Oct 02, 2009 10:22 pm    Post subject: RE:Help with solitaire game  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| I think you may have to specify a size for the vector.  I've had similar problems before | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		zero-impact
 
  
 
    
		 | 
		
		
			
				  Posted: Sat Oct 03, 2009 8:33 am    Post subject: RE:Help with solitaire game  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Already tried that, doesn't work. Not to mention it works perfectly fine in the other classes. | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		zero-impact
 
  
 
    
		 | 
		
		
			
				  Posted: Sun Oct 04, 2009 1:53 pm    Post subject: Re: Help with solitaire game  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Found the problem and I hate myself for it...
 
 
Forgot to add Mouse mouse; to one of my main header files >.< It was only in the .cpp file. | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		saltpro15
 
  
 
    
		 | 
		
		
			
				  Posted: Sun Oct 04, 2009 1:56 pm    Post subject: RE:Help with solitaire game  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| *slow clap* | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		 |