Error Compiling LNK2019

Hey everybody,

I'm having a problem getting my project to compile and I'd appreciate your feedback. I'm in my first semester of C++ in school so this is probably just a simple problem that I'm overlooking. Thanks!

Also, I've trimmed the bool functions at the end of Cards.cpp for space reasons.

Here's the error I'm getting from my project (using VS2010).

1
2
3
4
5
Warning	1	warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data	96	1	Lab13
Error	2	error LNK2019: unresolved external symbol "void __cdecl Sort(struct Hand * const)" (?Sort@@YAXQAUHand@@@Z) referenced
		in function "void __cdecl Deal(struct Card * const,struct Hand * const,unsigned long)"
		(?Deal@@YAXQAUCard@@QAUHand@@K@Z)	Cards.obj	Lab13
Error	3	error LNK1120: 1 unresolved externals	1	1	Lab13


And here are my files for the project.

Main.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
#include <iostream>

#include "Cards.h"

using namespace std;

void main ()
	{
	const	ULong	NumHands	(4);
		Card	Deck		[52];
		Hand	MyHands		[4];
		int	i;
		bool	Evaluating;

	Shuffle (Deck);
	Deal (Deck, MyHands, NumHands);
	cout << endl << endl;

	for (i = 0; i < NumHands; i++)
		{
		Evaluating = true;
		do {
		if ((IsRoyalFlush (MyHands [i])) == true)
		{
		cout << "Player " << i+1 << " has a ROYAL FLUSH!" << endl;
		Evaluating = false;
		break;
		}
		else
			if ((IsStraightFlush (MyHands [i])) == true)
			{
			cout << "Player " << i+1 << " has a STRAIGHT FLUSH!" << endl;
			Evaluating = false;
			break;
			}
			else
				if ((IsFlush (MyHands [i])) == true)
				{
				cout << "Player " << i+1 << " has a FLUSH!" << endl;
				Evaluating = false;
				break;
				}
				else
					if ((IsFourOfaKind (MyHands [i])) == true)
					{
					cout << "Player " << i+1 << " has FOUR OF A KIND!" << endl;
					Evaluating = false;
					break;
					}
					else
						if ((IsFullHouse (MyHands [i])) == true)
						{
						cout << "Player " << i+1 << " has a FULL HOUSE!" << endl;
						Evaluating = false;
						break;
						}
						else
							if ((IsThreeOfaKind (MyHands [i])) == true)
							{
							cout << "Player " << i+1 << " has THREE OF A KIND!" << endl;
							Evaluating = false;
							break;
							}
							else
								if ((IsTwoPair (MyHands [i])) == true)
								{
								cout << "Player " << i+1 << " has TWO PAIR!" << endl;
								Evaluating = false;
								break;
								}
								else
									if ((IsOnePair (MyHands [i])) == true)
									{
									cout << "Player " << i+1 << " has ONE PAIR!" << endl;
									Evaluating = false;
									break;
									}
									else
										{
										cout << "Player " << i+1 << " has no winning combination." << endl;
										Evaluating = false;
										break;
										}
			} while (!Evaluating);
		}
	cout << endl << endl;
	}


Cards.h
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
#ifndef	CARDS_H
#define	CARDS_H

typedef	unsigned long	ULong;

enum Suits	{Hearts = 3, Diamonds, Clubs, Spades};
enum Values	{Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace};

struct	Card
	{
	Suits	Suit;
	Values	Value;
	};

struct	Hand
	{
	Card	Crd [5];
	ULong	Vlu;
	};

void Deal		(Card [], Hand [], ULong);
void Display		(const Card &);
void Shuffle		(Card []);
void Sort		(Hand []);

bool IsRoyalFlush	(Hand &);
bool IsStraightFlush	(Hand &);
bool IsStraight		(Hand &);
bool IsFlush		(Hand &);
bool IsFourOfaKind	(Hand &);
bool IsFullHouse	(Hand &);
bool IsThreeOfaKind	(Hand &);
bool IsTwoPair		(Hand &);
bool IsOnePair		(Hand &);
bool IsHighCard		(Hand &);

#endif 


Cards.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
141
142
143
144
145
146
#include <iostream>
#include <memory.h>
#include <time.h>

#include "Cards.h"

using namespace std;

char *	ValueNames [] = {"Two",
			"Three",
			"Four",
			"Five",
			"Six",
			"Seven",
			"Eight",
			"Nine",
			"Ten",
			"Jack",
			"Queen",
			"King",
			"Ace"};

void Deal (Card Deck [], Hand MyHands [], ULong NumHands)
	{
	ULong	HandNo;
	ULong	CardNo;
	ULong	WhichCard (0);

	//Deal the hands
	for (CardNo = 0; CardNo < 5; CardNo++)
		for (HandNo = 0; HandNo < NumHands; HandNo++)
			MyHands [HandNo].Crd [CardNo] = Deck [WhichCard++];
	
	//Display the unsorted hands
	for (HandNo = 0; HandNo < NumHands; HandNo++)
		{
		cout << "\nPlayer " << HandNo + 1 << "'s Hand" << endl;
		for (CardNo = 0; CardNo < 5; CardNo++)
			Display (MyHands [HandNo].Crd [CardNo]);
		}

	//Sort the hands
	for (HandNo = 0; HandNo < NumHands; HandNo++)
		Sort (MyHands);

	//Display the sorted hands
	for (HandNo = 0; HandNo < NumHands; HandNo++)
		{
		cout << "\nPlayer " << HandNo + 1 << "'s Sorted Hand" << endl;
		for (CardNo = 0; CardNo < 5; CardNo++)
			Display (MyHands [HandNo].Crd [CardNo]);
		}
	}

//function for sorting the hands
void Sort (Hand MyHands)
	{
	ULong	i;
	ULong	NumHands (5);
	bool	Sorted;
	Card	TempCard;

	do	{
		Sorted = true;
		for (i = 0; i < NumHands; i++)
			if (MyHands.Crd [i].Value > MyHands.Crd [i+1].Value)
				{
				TempCard = MyHands.Crd [i];
				MyHands.Crd [i] = MyHands.Crd [i+1];
				MyHands.Crd [i+1] = TempCard;
				Sorted = false;
				}
			else;
		} while (!Sorted);
	}

//function for displaying the cards/hands on screen
void Display (const Card & Crd)
	{
	cout << ValueNames [Crd.Value] << " of " << (char) Crd.Suit << endl;
	}

//function for shuffling cards
void Shuffle (Card Deck [])
	{
	long	i;
	bool	Picked [52];
	long	WhichCard;

	srand (time (0));
	memset (Picked, false, 52 * sizeof (bool));
	for (i = 0; i < 52; i++)
		{
		while (Picked [WhichCard = rand () % 52]);
		Deck [i].Suit		= (Suits) ((WhichCard / 13) + Hearts);
		Deck [i].Value		= (Values) (WhichCard % 13);
		Picked [WhichCard]	= true;
		Display (Deck [i]);
		}
	}


//bool for royal flush
bool IsRoyalFlush (Hand & MyHand)
	{
	}

//bool for straight flush
bool IsStraightFlush (Hand & MyHand)
	{
	}

//bool for straight
bool IsStraight (Hand & MyHand)
	{
	}

//bool for flush
bool IsFlush (Hand & MyHand)
	{
	}

//bool for four of a kind
bool IsFourOfaKind (Hand & MyHand)
	{
	}

//bool for full house
bool IsFullHouse (Hand & MyHand)
	{
	}

//bool for three of a kind
bool IsThreeOfaKind (Hand & MyHand)
	{
	}

//bool for two pair
bool IsTwoPair (Hand & MyHand)
	{
	}

//bool for one pair
bool IsOnePair (Hand & MyHand)
	{
	}
Last edited on
You're written a function void Sort (Hand MyHands), which accepts a variable of type Hand, but you try to call Sort(struct Hand * const)" (i.e. you're trying to pass a pointer to a Hand, but the function doesn't take a pointer to a Hand; it takes a Hand).

Here's a call: Sort (MyHands);
What is MyHands? It's this: Hand MyHands [4];, an array of 4 hands, which of course decomposes to a pointer to Hand. You're trying to call a function you never wrote.


Somewhere you're converting a time_t object to an unsigned int, which it'll do for you, but it doesn't like it.
Last edited on
Thank you for the reply and please excuse my ignorance when it comes to functions and pointers.

Is this a simple naming issue or something much deeper that requires a redesign?

Should I be sending something different from the Sort call to the sort function? If so, should the format be something different in the header file to match? I've tried sending Sort (PlayerHands [HandNo].Crd [CardNo]); with void Sort (const Hand &); in the header but that gives me all kinds of errors.

Should I be trying to sort the cards inside of the Deal function where the Sort call is located?

I've spent hours on this and I just can't seem to get anywhere.
Topic archived. No new replies allowed.