Я использую заголовочные файлы, мои функции не распознаются. Точные ошибки, которые я получаю:
main.cpp: (текст + 0x67): неопределенная ссылка на resetDeck ()
main.cpp: (text + 0x6c): неопределенная ссылка на ‘deal ()’
main.cpp: (text + 0x71): неопределенная ссылка на ‘displayCards ()
Функции вызываются в строках 18, 19 и 20 main.cpp.
Вот код (да, я знаю, что я написал менеджер неправильно):
cardManger.h
#ifndef CARDMANGER_H_INCLUDED
#define CARDMANGER_H_INCLUDED
void resetDeck(void);
void deal(void);
void displayCards(void);
#endif
cardManger.cpp
#include <iostream>
#include <cstdlib>
#include <vector>
#include "cardManger.h"using namespace std;
int playerOneNumberOfCards = 7;
int playerTwoNumberOfCards = 7;
int playerThreeNumberOfCards = 7;
int playerFourNumberOfCards = 7;
vector<int> playerOnesHand(7);
vector<int> playerTwosHand(7);
vector<int> playerThreesHand(7);
vector<int> playerFoursHand(7);
int playerTwosCardMem[3];
int playerThreeCardMem[3];
int playerFoursCardMem[3];
int playerTwosUserMem[3];
int playerThreeUserMem[3];
int playerFoursUserMem[3];
int playerTwoMemCount;
int playerThreeMemCount;
int playerFourMemCount;
int deck[52];
void resetDeck(void){
deck[0] = 1;
deck[1] = 1;
deck[2] = 1;
deck[3] = 1;
deck[4] = 2;
deck[5] = 2;
deck[6] = 2;
deck[7] = 2;
deck[8] = 3;
deck[9] = 3;
deck[10] = 3;
deck[11] = 3;
deck[12] = 4;
deck[13] = 4;
deck[14] = 4;
deck[15] = 4;
deck[16] = 5;
deck[17] = 5;
deck[18] = 5;
deck[19] = 5;
deck[20] = 6;
deck[21] = 6;
deck[22] = 6;
deck[23] = 6;
deck[25] = 7;
deck[26] = 7;
deck[27] = 7;
deck[28] = 8;
deck[29] = 8;
deck[30] = 8;
deck[31] = 8;
deck[32] = 9;
deck[33] = 9;
deck[34] = 9;
deck[35] = 9;
deck[36] = 10;
deck[37] = 10;
deck[38] = 10;
deck[39] = 10;
deck[40] = 11;
deck[41] = 11;
deck[42] = 11;
deck[43] = 11;
deck[44] = 12;
deck[45] = 12;
deck[46] = 12;
deck[47] = 12;
deck[48] = 13;
deck[49] = 13;
deck[50] = 13;
deck[51] = 13;
}
void deal (void){
srand(time(0));
int r;
int s = 0;
for(int i = 8; i>0; i--){
if(i == 8){
playerOnesHand[7] = 0;
}else{
do{
s = (rand()%51)+1;
r = deck[s];
}while(r == 0);
playerOnesHand[--i] = r;
i++;
deck[s] = 0;
}
}
s = 0;
r = 0;
for(int i = 8; i>0; i--){
if(i == 8){
playerTwosHand[7] = 0;
}else{
do{
s = (rand()%51)+1;
r = deck[s];
}while(r == 0);
playerTwosHand[--i] = r;
i++;
deck[s] = 0;
}
}
s = 0;
r = 0;
for(int i = 8; i>0; i--){
if(i == 8){
playerThreesHand[7] = 0;
}else{
do{
s = (rand()%51)+1;
r = deck[s];
}while(r == 0);
playerThreesHand[--i] = r;
i++;
deck[s] = 0;
}
}
s = 0;
r = 0;
for(int i = 8; i>0; i--){
if(i == 8){
playerFoursHand[7] = 0;
}else{
do{
s = (rand()%51)+1;
r = deck[s];
}while(r == 0);
playerFoursHand[--i] = r;
i++;
deck[s] = 0;
}
}
}
void displayCards(void){
for(int i = playerOneNumberOfCards; i > 0; i--){
cout << playerOnesHand[i];
}
}
main.cpp
#include <iostream>
#include "Ai.h"#include "cardManger.h"using namespace std;
int numberOfPlayers;
bool gameIsOn;
string question;
/* Allocates memory for players*/
int main(void){
std::cout << "Welcome to Go Fish. Do you wish to play? If so enter Y. If not enter N. \n";
std::cin >> question;
if((question == "N") || (question == "n")){
return 0;
}
gameIsOn = true;
do{
resetDeck();
deal();
displayCards();
gameIsOn = false;
}while(gameIsOn);
return 0;
}
Спасибо.
Я обнаружил, что было не так. Я не связывал свои файлы с make-файлом. Спасибо за все комментарии.
Других решений пока нет …