I am pretty new to c++ programming. I am trying to set up a card and deck class. I keep getting a segmentation fault as an error and cant seem to figure out where.
This is my Deck.h
#ifndef _DECK_H
#define _DECK_H
#include "card.h"
#include <stack>
class Deck
{
public:
void initialiseCardDeck(int setNum,Deck deck);
stack <string> st1;
};
#endif
and this is my deck.cpp where i am trying to test if it works. Deck.cpp-
#include "card.h"
#include "deck.h"
#include <stack>
#include <iostream>
using namespace std;
Deck initialiseCardDeck(int setNum,Deck deck)
{
int i,k;
for(k=0;k<setNum;k++)
{
for(i=1;i<=13;i++)
{
Card c = Card(i,Card::hearts);
deck.st1.push(c.toString());
}
for(i=1;i<=13;i++)
{
Card c =Card(i,Card::spades);
deck.st1.push(c.toString());
}
for(i=1;i<=13;i++)
{
Card c =Card(i,Card::diamonds);
deck.st1.push(c.toString());
}
for(i=1;i<=13;i++)
{
Card c =Card(i,Card::clubs);
deck.st1.push(c.toString());
}
}
std::cout<<deck.st1.top();
}
int main()
{
Deck d;
d.st1.push("worked");
std::cout<<d.st1.top();
initialiseCardDeck(1,d);
}
Aucun commentaire:
Enregistrer un commentaire