Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with solitaire game
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zero-impact




PostPosted: 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 Smile


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
Sponsor
sponsor
DtY




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: Sun Oct 04, 2009 1:56 pm   Post subject: RE:Help with solitaire game

*slow clap*
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: