Hi all, when i tried to compile those files, my compiler told me that I have 3 errors
those errors are:
Compiling...
rowstackTest.cpp
c:\lab8\rowstacktest.cpp(17) : error C2065: 'faceDownCards' : undeclared identifier
c:\lab8\rowstacktest.cpp(17) : error C2228: left of '.pushFaceDownCard' must have class/struct/union type
c:\lab8\rowstacktest.cpp(17) : error C2275: 'Deck' : illegal use of this type as an expression
c:\lab8\deck.h(8) : see declaration of 'Deck'
Here is my RowstackTest.cpp
Code:
#include <iostream>
#include <stack>
#include "rowstack.h"
#include "deck.h"
#include "card.h"
using namespace std;
int main()
{
Deck MyDeck; // Instantiate a Deck object;
Rowstack MyRowstack; // Instantiate a Rowstack object;
for(int iCtr = 0; iCtr < 6; iCtr++)
{
faceDownCards.pushFaceDownCard(Deck[iCtr]);
}
return 0;
}
Here is my rowstack.cpp
Code:
//rowstack.cpp
#inclued <cstdlib>
#include <stack>
#include <iostream>
#include "rowstack.h"
using namespace std;
void Rowstack::pushFaceDownCard(const Card& card)
{
rowstack.push_back(card); //Adds a card to the Rowstack.
}
Card RowstackL::popFaceDownCard()
{
if ( empty() )
{
throw RowStackExceptions::RowstackEmpty;
}
return popFaceDownCards.top(); // returns the card at the top of the stack.
}
here is my rowstack.h
Code:
//rowstack.h
#ifndef rowstack_h
#define rowstack_h
#include <stack>
#include <cstdlib>
#include "card.h"
#include "deck.h"
class Rowstack
{
public:
void pushFaceDownCard(const Card& card); //Adds a card to the RowStack
Card popFaceDownCard(); //Returns the card at the top of the stack
bool isFaceDownEmpty() const; //Returns true if the stack containing the face down card is empty
private:
stack<Card> faceDownCards; // STL stack of Card ADT's
};
class RowstackException
{
public:
enum RowstackExceptions
{
RowstackEmpty
};
RowstackException( RowstackExceptions newException ) :
exception( newException ) {} //sets the private attribute exception to new exception
RowstackExceptions getException() const {return exception;} //returns the private attribute exception
private:
RowstackExceptions exception;
};
#endif
and that one is my deck.h
Code:
#ifndef deck_h
#define deck_h
#include <vector>
#include <cstdlib>
#include "card.h"
class Deck
{
public:
enum {NUM_CARDS = 52};
Deck(); // default constructor, sets the initial size of 52
void shuffle(); // method of shuffle cards
Card& operator[] (int); // Overload the [] operator.
private:
vector<Card> card; // STL vector of type card.
};
#endif
Last one is my card.h
Code:
#ifndef CARD_H
#define CARD_H
#include <iostream>
using namespace std;
class Card
{
public:
enum Rank
{
ACE,
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING
};
enum Suit
{
SPADES,
HEARTS,
CLUBS,
DIAMONDS
};
Card(); // Default constructor will initialize to Ace of Spades
Card( Rank newRank, Suit newSuit );
Rank getRank() const {return rank;}
Suit getSuit() const {return suit;}
void setRank( Rank newRank );
void setSuit( Suit newSuit );
private:
Rank rank;
Suit suit;
};
ostream& operator<<( ostream& os, const Card& card );
#endif;
Do i code it incorrectly inside the rowstackTest.cpp?
Can anyone tell me what's going on?
Thanks