First

I'm having some issues with a rather new concept to me.




I have a class that is giving me errors which I'm not quite understanding.
They are

Build started: Project: mp7, Configuration: Debug Win32 ------
1> code.cpp
1>c:\users\jordan\documents\visual studio 2010\projects\lad\lad\cards.h(42): warning C4832: token '.' is illegal after UDT 'cards'
1> c:\users\jordan\documents\visual studio 2010\projects\lad\lad\cards.h(10) : see declaration of 'cards'
1>c:\users\jordan\documents\visual studio 2010\projects\lad\lad\cards.h(42): error C2275: 'cards' : illegal use of this type as an expression
1>c:\users\jordan\documents\visual studio 2010\projects\lad\lad\cards.h(42): error C2228: left of '.face' must have class/struct/union
1>c:\users\jordan\documents\visual studio 2010\projects\lad\lad\cards.h(43): warning C4832: token '.' is illegal after UDT 'cards'
1> c:\users\jordan\documents\visual studio 2010\projects\lad\lad\cards.h(10) : see declaration of 'cards'
1>c:\users\jordan\documents\visual studio 2010\projects\lad\lad\cards.h(43): error C2275: 'cards' : illegal use of this type as an expression
1>c:\users\jordan\documents\visual studio 2010\projects\lad\lad\cards.h(43): error C2228: left of '.suit' must have class/struct/union
1>c:\users\jordan\documents\visual studio 2010\projects\lad\lad\cards.h(45): error C2143: syntax error : missing ';' before '.'
1>c:\users\jordan\documents\visual studio 2010\projects\lad\lad\cards.h(45): error C2143: syntax error : missing ';' before '.'
1>c:\users\jordan\documents\visual studio 2010\projects\lad\lad\cards.h(46): error C2143: syntax error : missing ';' before '.'
1>c:\users\jordan\documents\visual studio 2010\projects\lad\lad\cards.h(46): error C2143: syntax error : missing ';' before '.'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is where they are coming from;

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
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <iomanip>

using namespace std;

class cards
{
  private:
	int face;
	char suit;
	
  public:
	  cards(int = 0, char = ' ');
		
	  void display();
	  void swap(cards&);
	  
	  void setCards(int, char);
	  //Getters
	  int getFace();
      char getSuit();

};


//Functions
cards::cards(int f, char s)
{
	face = f;
	suit = s;
}

void cards::swap(cards& c)
{
	cards temp;

	temp.face = c.face;
	temp.suit = c.suit;
	c.face = cards.face;
	c.suit = cards.suit;

	cards.face = temp.face;
	cards.suit = temp.suit;

}

void cards::display()
{
	switch(face)
	{
	case 11: cout <<"J" << endl;
		break;
	case 12: cout << "Q" << endl;
		break;
	case 13: cout << "K" << endl;
	    break;
	case 1: cout << "A" << endl;
	default: cout << face;
	}
	
	cout << suit;
}

void cards::setCards(int f, char s)
{
	face = f;
	suit = s;
}

int cards::getFace()
{	
	return face;

}

char cards::getSuit()
{
	return suit;
}


missing ';' before '.'
When I looked this up the error c2143 it said missing token 1 before token 2. I'm not sure how to interpret this.
Any help please and thank you with understand standing these issues?
1
2
3
4
5
6
7
8
9
10
11
12
13
void cards::swap(cards& c)
{
	cards temp;

	temp.face = c.face;
	temp.suit = c.suit;

	c.face = face;
	c.suit = suit;

	face = temp.face;
	suit = temp.suit;
}
Thank you that helped I'm now getting other issues involving my array I think. My numbers are off. The sample for this is supposed to output this for the first two lines
Hand for Andy is : JH QH Value of this hand is 20
Hand for Bob is : QC 2H Value of this hand is 12

In stead I'm getting the right cards but for the last part "Value of this hand"
I get 23 for the first and some crap for the second. 1818322258. I'm pretty confused by this because the array that this is coming from is initialized so what gives?
I think that if I can get this part that the other things that are off will fall into line. This is the function below.

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
void deal(string playersName[],int cardsT[])
{
	int counter = 0;
	cout << "Deal two cards to everyone" << endl;
	for(int i = 0; i < TWOCARD; i++)
	{
		for( int j = 0; j < PLAYERCOUNT; j++)
		{
			cardsT[j] += hand[counter++].getFace();

		}

	}
	
	//Display
	for( int k = 0; k < PLAYERCOUNT; k++)
	{
		cout << "Hand for " << playersName[k] << " is : " ;
		hand[k].display();  
		cout << " and " ;
		hand[k + PLAYERCOUNT].display();
		cout << " Value for this hand is " << cardsT[k] << endl;
	}
	 cout << endl <<endl;
}


Any help would be great.
Oh and this is the constants that were used
1
2
3
4
const int PLAYERCOUNT = 7;
const int GAMELIMIT = 21;
const int DEALER = 16; 
const int TWOCARD = 2;


Thanks
Topic archived. No new replies allowed.