Can one of you gurus give me some help please. I am a new programmer so please bear with me. I have a header file called Deck.h and a cpp file called Deck.cpp. In my header file, I have a class called Deck which has prototype function called createPack as one of its member functions. the createPack function is defined in Deck.cpp. I also have a file called PokerEngine.cpp which holds my main function. However, when I create an instance of class Deck and try and call the function createPack, I get undefined reference errors. I have tried using both the "." and "->" operators and I am still getting the errors. I was hoping you guys will be able to help me solve this.

Deck.h header file

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

using namespace std;


namespace pack{
	 struct card{

	 		// this holds the description of the card e.g. "King Of"
	 		std::string card_name;
	 		
	 		//card type e.g. "Hearts", Spades, etc
	 		std::string card_type;
	 		/*
	 		 * the value of the card e.g, 2,3 6 etc Note that Jack = 10
	 		 * Queen = 11, King = 12, Ace = 13
	 		 */
	 		int card_value;
	 		};
	 		
}
class Deck

{
	pack::card deck;
	
public:
	Deck();
	 ~Deck();
	 
		// returns a card
	pack::card getCard();

       // create a card
	inline void createCard(string card_name, string card_type, int card_value);
	
	//retutrn a pack of cards as a vector
	vector  <pack::card>getDeckOfcards();
	
	//reset a card variable
	void resetCard(pack::card card);
	
	//create a pack of cards
	
	vector <pack::card>createPack();

	};

Deck.cpp file

#include "Deck.h"
#include <iostream>
#include <vector>
using namespace std;
using namespace pack;



	
	/*defines a deck with a return type of deck i.e. Note that 
	 * the return type deck is from the namespace pack which is declared and defined in
	 * the the header file "Deck.h"
	 */ 
   
 extern pack::card deck;
    

/*defines a getCard with a return type of deck i.e. Note that 
 * the return type deck is from the namespace pack which is declared and defined in
 * the the header file "Cards.h"
 */ 
pack::card getCard();

//vector holding a deck of cards
	vector <pack::card>deckOfCards;

// 
inline void Deck::createCard(string card_name, string card_type, int card_value)
{
	deck.card_name=card_name; 
		deck.card_type = card_type; 
		deck.card_value= card_value;
};

//return deck of cards
//vector  <pack::card>getDeckOfcards();

//reset a card  variable
//void resetCard(pack::card card);

vector <pack::card>Deck::createPack(){
	
	int type = 0;
	int value = 2;
	string card_name, card_type; 
	int card_value;
	
switch(type){
case 0:
	card_type = "Heart";
	break;
case 1:
	card_type = "Spade";
	break;

case 2:
	card_type = "Clubs";
	break;

case 3:
	card_type = "Diamond";
	break;
}

switch(value){

case 2: 
card_name = "2 of ";
break;

case 3: 
card_name = "3 of ";
break;

case 4: 
card_name = "4 of ";
break;

case 5: 
card_name = "5 of ";
break;

case 6: 
card_name = "6 of ";
break;

case 7: 
card_name = "7 of ";
break;

case 8: 
card_name = "8 of ";
break;

case 9: 
card_name = "9 of ";
break;

case 10: 
card_name = "10 of ";
break;

case 11: 
card_name = "Jack of ";
break;

case 12: 
card_name = "Queen of ";
break;

case 13: 
card_name = "King of ";
break;

case 14:
card_name = "Ace of ";
break;
}
	vector <pack::card>::iterator iter;
 for (;type<4;type++){
	 for (;value<15;value++){
		deck.card_name = card_name;
		deck.card_type = card_type;
		deck.card_value = value;
		
		 deckOfCards.push_back(deck);
		 resetCard(deck);
		 
 }
	 value = 2;
}
 return deckOfCards;
}


Deck::Deck()
{
	
	
}

Deck::~Deck()
{
}

pack::card Deck::getCard(){
	
	return deck;
}

vector <pack::card> Deck::getDeckOfcards(){
	return deckOfCards;
}



void Deck::resetCard(pack::card card){
	card.card_name="";
	card.card_type= "";
	card.card_value = 0;
}

PokerEngine.cpp file

#include <string.h>
#include "Player.h"
#include "Deck.h"
#include <iostream>
using namespace std;
using namespace pack;


class Poker{
	
};

int main(){
	

	string pl_name = "Player1";
	int pl_id = 0;
	Deck *dk; = new Deck;
	
	dk->createPack();
	Player *pl = new Player(pl_name, pl_id);	
dk=0;
delete dk;
    
   
	
	return 0;
}

Compiler Errors


**** Build of configuration Debug for project Poker ****

**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -oPokerGameEngine.o ..\PokerGameEngine.cpp
..\PokerGameEngine.cpp: In function `int main()':
..\PokerGameEngine.cpp:21: warning: unused variable 'pl'
g++ -O0 -g3 -Wall -c -fmessage-length=0 -oDeck.o ..\Deck.cpp
..\Deck.cpp: In member function `std::vector<pack::card, std::allocator<pack::card> > Deck::createPack()':
..\Deck.cpp:48: warning: unused variable 'card_value'
g++ -oPoker.exe lottery.o PokerGameEngine.o Player.o Deck.o
PokerGameEngine.o: In function `main':
D:/C_Files_02.03.2007/MyOwnDevelopedPrograms/Poker/Debug/../PokerGameEngine.cpp:20: undefined reference to `Deck::createPack()'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 4250 ms.

Change Deck *dk; = new Deck; in the main() function
To Deck *dk = new Deck;

Thanks. that was a typo. Anyway, I've resolved the problem. It was a linker error. I just updated my compiler i.e. mingw 3.4.5 to the latest of 5.1.3 and it works now. Thanks for your help anyway.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.