error LNK2019 HELP!

I know there are a few posts about this error but I've looked at them and haven't been able to solve my case,
link to project:
https://www.dropbox.com/s/mhh3lf4c49b9a16/lab2poker.zip

my headers:
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

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

enum suit_t{nad =0, clubs,diamond,heart,spade};
enum rank_t{nad1 =0,one, two,three,four,five,six,seven,eight,nine,ten,jack,queen,king,ace};


class Card
{
public:
	Card();
	Card(suit_t s, rank_t r);
	int getvalue();
	suit_t getsuit();
	rank_t getrank();
	string getsuitname();
	string getrankname();
	void setsuit(suit_t suit);
	void setrank(rank_t rank);



private:
suit_t mysuit ;
rank_t myrank;


};

#endif 

deck.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "cards.h"


class Deck
{
private:
Card _cards[52];
bool used_cards[52];
public:
	Deck();
	void resetDeck();
	Card getnextcard();
};

hand.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
#include "cards.h"


class Hand
{
private:
	Card _cards[5];
public:
	Hand();
	Hand(suit_t s, rank_t r);
	void setCard(int position, Card card);
	Card getCard(int position);
	Card highCard();
	bool haspair();
	bool hastwopair();
	bool hasThreeofakind();
	bool hasstraight();
	bool hasFlush();
	bool hasfullhouse();
	bool hasfourofakind();
	void sort_Cards();
	int check_hand(Hand hand);

};

.cpp files
deck.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
#include "deck.h"

Deck :: Deck()
{
	resetDeck();
}

void Deck::resetDeck()
{
	int counter = 0;
	for( int suit = 1;suit <= 4;suit ++)
	{
		for(int rank =2;rank <=14; rank++)
		{
			_cards[counter] = Card((suit_t) suit,(rank_t) rank);
			counter ++;
		}
	}
	for( int i = 0;i <52;i++)
	{
		used_cards[i] = true;
	}

}

Card Deck ::getnextcard()
{
	int sel = rand() % 52;
	while(used_cards[sel] == false)
	{
			int sel = rand() % 53;
	}
	used_cards[sel] = false;
	return _cards[sel];
}

part of hands.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
#include "hand.h"



Hand :: Hand()
{
	for( int i = 0; i<5;i++)
	{
	_cards[i] = Card(nad,nad1);
	}

}

Hand :: Hand(suit_t s, rank_t r)
{
	for( int i = 0; i<5;i++)
	{
	_cards[i] = Card(s,r);
	}
}



	void Hand:: setCard(int position, Card card)
	{
		_cards [position-1] = card;
	}

	Card Hand :: getCard(int position)
	{
		return _cards[position-1];
	}

main:
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
#include "cards.h"
#include "deck.h"
#include "hand.h"

int main()
{

	int bust =0, compbust =0, selection[5] ={0}, comphandvalue =0;
	char player_choice = 'H';
	Deck mydeck();
	Card mycard(nad,nad1), compcard(nad,nad1);
	Hand myhand(), comphand();
	mydeck().resetDeck();
	
	


	for (int i = 0; i<5; i++)
	{
		myhand().setCard(i, mydeck().getnextcard());
		cout<<i +1<<". "<< myhand().getCard(i).getrankname()<<
			" of "<<myhand().getCard(i).getsuitname()<<endl;
	}
	cout<< " Which cards would you like to put back(1-5)"<<endl;
	cin>>selection[0];
		for (int i=0;i<4;i++)
		{
			if(selection[i]>0 && selection[i]<6)
			{
				myhand().setCard(selection[i]+1, mydeck().getnextcard());
				cin>> selection[i+1];
			}else if(i==-1)
			{
				break;
			}
		}
		

		cout<<"your new cards are:"<<endl;
		for (int i = 0; i<5; i++)
	{
		cout<<i +1<<". "<< myhand().getCard(i).getrankname()<<
			" of "<<myhand().getCard(i).getsuitname()<<endl;
	}

		//computer


		cout<< "the computers card are"<<endl;
		for (int i = 0; i<5; i++)
	{
		comphand().setCard(i, mydeck().getnextcard());
		cout<<i +1<<". "<<comphand().getCard(i).getrankname()<<
			" of "<<comphand().getCard(i).getsuitname()<<endl;
	}
		/*comphandvalue = checkhand(comphand());
		switch (comphandvalue):
		case(5-8)
			break;
		case(
		*/




}

the resulting errors are :
main.obj : error LNK2019: unresolved external symbol "class Deck __cdecl mydeck(void)" (?mydeck@@YA?AVDeck@@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "class Hand __cdecl myhand(void)" (?myhand@@YA?AVHand@@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "class Hand __cdecl comphand(void)" (?comphand@@YA?AVHand@@XZ) referenced in function _main

I cannot figure out how to solve these issues, all help is appreciated
closed account (jwkNwA7f)
It looks like, you defined them, but never wrote the actually typed out the function.

EDIT: By "them", I meant: mydeck, myhand, and comphand.
Last edited on
Sorry I just started learning c++ and still getting the hang of it, but how would I go about solving this, am I initializing it wrong or am I forgetting something in the code??
closed account (jwkNwA7f)
Oh, I'm sorry I had a wrong idea. Please discard what I previously said. I am not sure what the problem is, sorry.

EDIT: You only need to use the parentheses when you define it:
HAND myhand();
When you use it, just use:
myhand.setCard(...);
You do this using mydeck, myhand, and comphand.
Last edited on
when I do
myhand.setCard(...)
I get an error saying "error expression must have a class type"(only myhand is underlined).
You only need to use the parentheses when you define it:
HAND myhand();

You don't need it there either and it won't work because operator() is not defined.

http://stackoverflow.com/questions/356950/c-functors-and-their-uses
Last edited on
ok so now on the ones i changed to this format
myhand.setCard(...) ;
all the ones that I changed now give this error:
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(18): error C2228: left of '.setCard' must have class/struct/union

which to my understanding would be that my class is somehow not set up right, but comparing these to my CARD class( which isn't throwing errors) I don't see any difference
Did you remove the parentheses behind all of your object names?

For example line 20 in main.cpp should be: myhand.setCard(i, mydeck.getnextcard());


Edit : typo
Last edited on
Yes I changed all of them to to be like

myhand.setCard(i, mydeck.getnextcard());

Now I have a lot of errors, here is the full error list:

1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(18): error C2228: left of '.setCard' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(18): error C2228: left of '.getnextcard' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(19): error C2228: left of '.getCard' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(19): error C2228: left of '.getrankname' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(20): error C2228: left of '.getCard' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(20): error C2228: left of '.getsuitname' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(28): error C2228: left of '.setCard' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(28): error C2228: left of '.getnextcard' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(40): error C2228: left of '.getCard' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(40): error C2228: left of '.getrankname' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(41): error C2228: left of '.getCard' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(41): error C2228: left of '.getsuitname' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(50): error C2228: left of '.setCard' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(50): error C2228: left of '.getnextcard' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(51): error C2228: left of '.getCard' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(51): error C2228: left of '.getrankname' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(52): error C2228: left of '.getCard' must have class/struct/union
1>c:\users\chase\documents\visual studio 2012\projects\lab2poker\lab2poker\main.cpp(52): error C2228: left of '.getsuitname' must have class/struct/union
1> hand.cpp
Okay, I downloaded your project and changed main.cpp to this:
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
int main()
{
	int bust =0, compbust =0, selection[5] ={0}, comphandvalue =0;
	char player_choice = 'H';
    Deck mydeck;
    Card mycard(nad, nad1);
    Card compcard(nad, nad1);
    Hand myhand;
    Hand comphand;
    mydeck.resetDeck();
	for (int i = 0; i<5; i++)
    {

        myhand.setCard(i, mydeck.getnextcard());
        cout<<i +1<<". "<< myhand.getCard(i).getrankname()<<
            " of "<<myhand.getCard(i).getsuitname()<<endl;
	}
	cout<< " Which cards would you like to put back(1-5)"<<endl;
	cin>>selection[0];
		for (int i=0;i<4;i++)
		{
			if(selection[i]>0 && selection[i]<6)
			{
                myhand.setCard(selection[i]+1, mydeck.getnextcard());
				cin>> selection[i+1];
			}else if(i==-1)
			{
				break;
			}
		}
		
		cout<<"your new cards are:"<<endl;
		for (int i = 0; i<5; i++)
	{
        cout<<i +1<<". "<< myhand.getCard(i).getrankname()<<
            " of "<<myhand.getCard(i).getsuitname()<<endl;
	}

		//computer


		cout<< "the computers card are"<<endl;
		for (int i = 0; i<5; i++)
	{
        comphand.setCard(i, mydeck.getnextcard());
        cout<<i +1<<". "<<comphand.getCard(i).getrankname()<<
            " of "<<comphand.getCard(i).getsuitname()<<endl;
	}
		/*comphandvalue = checkhand(comphand());
		switch (comphandvalue):
		case(5-8)
			break;
		case(
		*/

}


The only other problem that I found was in hand.cpp. You are indexing out of bounds with "position-1"
1
2
3
4
5
6
7
8
9
10
11
	void Hand:: setCard(int position, Card card)
	{
//        _cards [position-1] = card;
        _cards [position] = card;
	}

	Card Hand :: getCard(int position)
	{
//        return _cards[position-1];
        return _cards[position];
	}

Output:
1
2
3
4
5
6
1. 2 of spade
2. jack of diamond
3. king of heart
4. 6 of spade
5. 3 of clubs
 Which cards would you like to put back(1-5)

ok thanks so much I think that fixed it

edit: I diddn't realize you couldn't realize you can't call a class on the same line thanks so much I probably looked over that a 100 times
Last edited on
You're welcome.

I diddn't realize you couldn't realize you can't call a class on the same line
It is okay to instantiate objects on the same line as you did originally.
See "Declaring a variable" here: http://www.learncpp.com/cpp-tutorial/21-basic-addressing-and-variable-declaration/

One other thing: You need to seed the random number generator or you will get the same hands every run. http://www.cplusplus.com/reference/cstdlib/srand/

HTH
Topic archived. No new replies allowed.