Author |
Message |
zero-impact
![](http://compsci.ca/v3/uploads/user_avatars/872397874480c7089d4888.gif)
|
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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
DtY
![](http://compsci.ca/v3/uploads/user_avatars/8576159234be48b7a8b0e8.png)
|
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++?) |
|
|
|
|
![](images/spacer.gif) |
zero-impact
![](http://compsci.ca/v3/uploads/user_avatars/872397874480c7089d4888.gif)
|
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. |
|
|
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
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 |
|
|
|
|
![](images/spacer.gif) |
zero-impact
![](http://compsci.ca/v3/uploads/user_avatars/872397874480c7089d4888.gif)
|
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. |
|
|
|
|
![](images/spacer.gif) |
zero-impact
![](http://compsci.ca/v3/uploads/user_avatars/872397874480c7089d4888.gif)
|
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. |
|
|
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
Posted: Sun Oct 04, 2009 1:56 pm Post subject: RE:Help with solitaire game |
|
|
*slow clap* |
|
|
|
|
![](images/spacer.gif) |
|