Help with minor errors in program

I'm encountering two small errors in my code and I'm not sure how to fix them.

1. Line 1 in PokerCard.h is returning an error of: redefinition of `class PokerCard'
2. Line 138 in PokerCard.cpp is returning an error of: Member declaration not found.

PokerCard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class PokerCard {
	enum  SuitType {NO_SUIT, CLUBS, DIAMONDS, HEARTS, SPADES};
public:
//	enum  class SuitType {NO_SUIT, CLUBS, DIAMONDS, HEARTS, SPADES};
//	enum SuitType {NO_SUIT, CLUBS, DIAMONDS, HEARTS, SPADES};
//	explicit PokerCard (int, SuitType); // constructor initialize rank and suit
//	enum SuitType {NO_SUIT, CLUBS, DIAMONDS, HEARTS, SPADES};
	explicit PokerCard (); // constructor initialize rank and suit
	int getRank() const; // retrieve card value
//	SuitType getSuit() const; // retrieve card value
	int getSuit() const; // retrieve card value
	void setRank(int);   // set card value
//	void setSuit(SuitType);  // set suit
	int setSuit(int);  // set suit
	void DisplayCard();
private:
	char Rank; // value of a card
//	SuitType Suit; // suit of a card
	int Suit; // suit of a card
};
// end of class PokerCard 



PokerCard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Member-function definitions for class PokerCard
#include <iostream>
#include "PokerCard.h"
using namespace std;
//enum class SuitType : unsigned int {NO_SUIT, CLUBS, DIAMONDS, HEARTS, SPADES};
enum  SuitType {NO_SUIT, CLUBS, DIAMONDS, HEARTS, SPADES};

// constructor to initialize value and suit
PokerCard::PokerCard()
{
   Rank = 0;
   Suit = SuitType::NO_SUIT;
} // end function constructor


void PokerCard::DisplayCard()
// display the suit and value of an individual card
{
	// display Rank
	if ( 1 == Rank )
	{
		cout << 'A';
	}
	else if (( 2 <= Rank ) && ( Rank <= 10 ))
	{
		cout << Rank;
	}
	else	// for face cards
	{
		switch ( Rank )
		{
		   case 11:
			      cout << 'J';
			      break;
		   case 12:
			      cout << 'Q';
			      break;
		          break;
		   case 13:
			      cout << 'K';
			      break;
		   default:
				cout << "Invalid rank value" << endl;
		}  //end switch case
	}  //end else

	// display suit
	switch (Suit)
	{
	   case CLUBS:
		          cout << " Clubs  ";
		          break;
	   case DIAMONDS:
	          cout << " Diamonds  ";
	          break;
	   case HEARTS:
	          cout << " Hearts  ";
	          break;
	   case SPADES:
	          cout << " Spades  ";
	          break;
	   default:
			cout << "Invalid suit value" << endl;
	} //end switch case
}  // end function displayCard


//***************************************************************************
//                                                                          *
// MemberFunctionName: getRank                                              *
// Description: This function retrieves data member Rank                    *
// Modification history: version 1                                          *
//                                                                          *
//**************************************************************************/

// function to retrieve the rank of a card
int PokerCard::getRank() const {
	return Rank;
} // end function getRank


//***************************************************************************
//                                                                          *
// MemberFunctionName: getSuit                                              *
// Description: This function retrieves data member Suit                    *
// Modification history: version 1                                          *
//                                                                          *
//**************************************************************************/
// function to retrieve the suit of a card
//SuitType PokerCard::getSuit() const {
int PokerCard::getSuit() const {
	return Suit;
} // end function getSuit



//***************************************************************************
//                                                                          *
// MemberFunctionName: setRank                                              *
// Description: This function takes a parameter as input and sets the       *
//              value of data member Suit                                   *
// Modification history: version 1                                          *
//                                                                          *
//**************************************************************************/

// function to set a valid value to data member Rank
void PokerCard::setRank( int value )  {
	const int MAX_RANK = 13;
	if (( value >= 1 ) && (value <= MAX_RANK ))  // between ACE (1) to 13
	   {
		  Rank = value;
       }
	else
	   {
		  cout << "Invalid card rank " << endl;
	   }
} // end function setRank


//***************************************************************************
//                                                                          *
// MemberFunctionName: setSuit                                              *
// Description: This function takes a parameter as input and sets the       *
//              value of data member Suit                                   *
// Modification history: version 1                                          *
//                                                                          *
//**************************************************************************/

// function to set a valid value to data member Suit
void PokerCard::setSuit( SuitType suit )  {
	if ((suit == CLUBS) || (suit == DIAMONDS) ||
		(suit ==HEARTS) || (suit == SPADES))
	   {
		  Suit  = suit;
       }
	else
	   {
		  cout << "Invalid card suit " << endl;
	   }
} // end function setSuit 
This is the thing with classes: Scope.

It is very hard to tell what is wrong. You have two variables: Suit, and suit. I would find it easy enough to get the two mixed up. When you refer to members of a class, from within a member of the class, use the class namespace to define the scope:

Suit = PokerCard::suit;

Now, I don't personally see anything wrong, but your code is somwhat difficult to read due to the similar naming fo your variables.

This isn't a syntax problem, but it does make it a LOT easier to spot errors when they do arise in these situations.
For your first error, try using include guards.

For your 2nd error, your header defines int setSuit(int); while your .cpp implements void PokerCard::setSuit( SuitType suit ).
Topic archived. No new replies allowed.