0

I've got an error with the linker but cannot figure out what it is.

It might be to do with how hand is a child of cards. There is also an issue with newGame.cpp which I cannot figure out

The errors are:

*LNK2019 : Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "public: __cdecl cards::cards(void)" (??0cards@@QEAA@XZ) referenced in function "public: __cdecl hand::hand(int)" (??0hand@@QEAA@H@Z)

LNK2019: Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "public: __cdecl dealerHand::dealerHand(int)" (??0dealerHand@@QEAA@H@Z) referenced in function "public: void __cdecl newGame::dealCards(class std::vector<class bet,class std::allocator >)" (?dealCards@newGame@@QEAAXV?$vector@Vbet@@V?$allocator@Vbet@@@std@@@std@@@Z)

LNK2019:Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "public: __cdecl splitHand::splitHand(int,class std::vector<class std::basic_string<char,struct std::char_traits,class std::allocator >,class std::allocator<class std::basic_string<char,struct std::char_traits,class std::allocator > > >)" (??0splitHand@@QEAA@HV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@Z) referenced in function "public: void __cdecl newGame::dealCards(class std::vector<class bet,class std::allocator >)" (?dealCards@newGame@@QEAAXV?$vector@Vbet@@V?$allocator@Vbet@@@std@@@std@@@Z)*

this is my hand.cpp file.

#include <iostream>
#include <random>
#include<vector>
#include<ctime>
#include <iterator>
#include <Windows.h>
#include <conio.h>
#include <fstream>
#include <sstream>
#include "headerFile.h"
using namespace std;
using std::vector;
hand::hand(int PlayNo) {
    playNo = PlayNo;
}
void hand::dealCard() {
    string card = shuffledDeck.back();
    playerHand.push_back(card);
    shuffledDeck.pop_back();

    if (shuffledDeck.size() == 0) {
        this->shuffleDeck();
    }

};
vector<string> hand::getHand() {
    return playerHand;
}

int hand::getHandTotal() {
    int handTotal = 0;
    for (int i = 0; i < playerHand.size(); i++) {
        if (playerHand[i][0] == '2') {
            handTotal += 2;
        }
        else if (playerHand[i][0] == '3') {
            handTotal += 3;
        }
        else if (playerHand[i][0] == '4') {
            handTotal += 4;
        }
        else if (playerHand[i][0] == '5') {
            handTotal += 5;
        }
        else if (playerHand[i][0] == '6') {
            handTotal += 6;
        }
        else if (playerHand[i][0] == '7') {
            handTotal += 7;
        }
        else if (playerHand[i][0] == '8') {
            handTotal += 8;
        }
        else if (playerHand[i][0] == '9') {
            handTotal += 9;
        }
        else if (playerHand[i][0] == '1') {
            handTotal += 10;
        }
        else if (playerHand[i][0] == 'J' || playerHand[i][0] == 'Q' || playerHand[i][0] == 'K') {
            handTotal += 10;
        }
        else if (playerHand[i][0] == 'A') {
            handTotal += 11;
            if (handTotal > 21) {
                handTotal -= 10;
            }
        }
    }
    for (int i = 0; i < playerHand.size(); i++) {
        if (playerHand[i][0] == 'A') {
            if (handTotal > 21) {
                handTotal -= 10;
            }
        }
    }
    return handTotal;
}
void hand::displayHand() {
    for (auto ele : playerHand) {
        cout << ele << endl;
    }
    cout << this->getHandTotal() << endl;

}

bool hand::checkBust() {
    if (this->getHandTotal() > 21) {
        return true;
    }
    else {
        return false;
    }
}

void hand::resetHand() {
    playerHand = {};
}
vector<string> hand::split() {
    vector<string> playerHand2;
    string card = shuffledDeck.back();
    playerHand2.push_back(playerHand.back());
    playerHand.pop_back();
    playerHand.push_back(card);
    shuffledDeck.pop_back();
    card = shuffledDeck.back();
    playerHand2.push_back(card);
    shuffledDeck.pop_back();
    return playerHand2;
}

this is the newGame.cpp file

#include <iostream>
#include <random>
#include<vector>
#include<ctime>
#include <iterator>
#include <Windows.h>
#include <conio.h>
#include <fstream>
#include <sstream>
#include "headerFile.h"
using namespace std;
using std::vector;
newGame::newGame(int NoOfPlayers) {
    noOfPlayers = NoOfPlayers;
}
void newGame::dealCards(vector<bet> bets) {
    srand(time(0));
    string split;
    dealerHand DealerHand(999);
    dealer.push_back(DealerHand);
    for (int i = 1; i <= noOfPlayers; i++) {
        hand Hand(i);
        hands.push_back(Hand);
    }

    for (int c = 1; c <= 2; c++) {
        for (int i = 0; i < hands.size(); i++) {
            hands[i].dealCard();
            for (auto ele : hands) {
                ele.shuffledDeck.pop_back();
            }
        }
        DealerHand.dealCard();

    }
    for (int c = 0; c < 2; c++) {
        system("CLS");
        for (int i = 0; i < hands.size(); i++) {
            cout << "--------------------------------------------------" << endl;
            cout << "Player " << hands[i].playNo << endl;
            vector<string> playerHand = hands[i].getHand();
            if (c == 0) {
                cout << playerHand[0] << endl;
            }
            else {
                cout << playerHand[0] << endl;
                cout << playerHand[1] << endl;
                cout << hands[i].getHandTotal() << endl;
                if (bets[i].balance >= bets[i].betAmount * 2) {
                    if (playerHand[0][0] == playerHand[1][0]) {
                        while (!cont) {
                            try {
                                cout << "Would you like to split? (y/n) " << endl;
                                cin >> split;
                                if (split == "y" || split == "n") {
                                    cont = true;
                                }
                                else {
                                    throw(split);
                                }
                            }
                            catch (string split) {
                                cout << "Input must be 'y' or 'n'" << endl;
                            }
                        }
                        if (split == "y") {
                            split = true;
                            vector<string> playerHand2 = hands[i].split();
                            bets[i].splitBet();
                            splitHand SplitHand(hands[i].playNo, playerHand2);
                            splitHands.push_back(SplitHand);
                            cout << "New hands:\n New Hand: " << endl;
                            hands[i].displayHand();
                            cout << "\n Split Hand: " << endl;;
                            SplitHand.displayHand();
                        }
                    }

                    cont = false;
                    if (hands[i].getHandTotal() > 8 && hands[i].getHandTotal() < 12) {
                        while (!cont) {
                            try {
                                cout << "Would you like to double down? (y/n) " << endl;
                                cin >> doubleDown;
                                if (doubleDown == "y" || doubleDown == "n") {
                                    cont = true;
                                }
                                else {
                                    throw(doubleDown);
                                }
                            }
                            catch (string doubleDown) {
                                cout << "Input must be 'y' or 'n'" << endl;
                            }
                        }
                    }
                }


            }
            Sleep(1000);
        }

        vector<string> dealHand = DealerHand.getOrgHand();
        cout << "--------------------------------------------------" << endl;
        cout << "Dealer " << endl;
        if (c == 0) {
            cout << dealHand[0] << endl;
        }
        else {
            cout << dealHand[0] << endl;
            cout << dealHand[1] << endl;

        }
        Sleep(1000);

    }

}

void newGame::hitOrStand() {
    int hOs;

    for (int i = 0; i < hands.size(); i++) {
        bool hit = true;
        while (hit == true) {
            if (doubleDown == "y") {
                hands[i].dealCard();
                cout << "--------------------------------------------------" << endl;
                cout << "\rNew hand " << endl;
                hands[i].displayHand();
                if (hands[i].checkBust() == true) {
                    cout << "Bust!" << endl;
                }
                hit = false;
                break;
            }
            cout << "--------------------------------------------------" << endl;
            cont = false;
            while (!cont) {
                try {
                    cout << "Player " << hands[i].playNo << " Hit(1) or Stand?(2) ";
                    cin >> hOs;
                    if (hOs == 1 || hOs == 2) {
                        cont = true;
                    }
                    else {
                        throw(hOs);
                    }
                }
                catch ([[maybe_unused]] int hOs) {
                    cout << "Input must be '1' or '2'" << endl;
                }
            }
            if (hOs == 1) {
                hands[i].dealCard();
                cout << "--------------------------------------------------" << endl;
                cout << "\rNew hand " << endl;
                hands[i].displayHand();
                if (hands[i].checkBust() == true) {
                    cout << "Bust!" << endl;
                    hit = false;
                }
            }
            else {
                hit = false;
            }
        }
        if (splitHands.size() > 0) {
            hit = true;
            while (hit == true) {
                for (auto ele : splitHands) {
                    if (ele.No == hands[i].playNo) {
                        cout << "--------------------------------------------------" << endl;
                        cont = false;
                        while (!cont) {
                            try {
                                cout << "Player " << hands[i].playNo << " Second hand Hit(1) or Stand?(2) " << endl;
                                cin >> hOs;
                                if (hOs == 1 || hOs == 2) {
                                    cont = true;
                                }
                                else {
                                    throw(hOs);
                                }
                            }
                            catch ([[maybe_unused]] int hOs) {
                                cout << "Input must be '1' or '2'" << endl;
                            }
                        }

                        if (hOs == 1) {

                            splitHands[hands[i].playNo - 1].dealCard();
                            cout << "--------------------------------------------------" << endl;
                            cout << "\rNew hand " << endl;
                            splitHands[hands[i].playNo - 1].displayHand();
                            if (splitHands[hands[i].playNo - 1].checkBust() == true) {
                                cout << "Bust!" << endl;
                                hit = false;
                            }
                        }
                        else {
                            hit = false;
                        }
                    }
                }
            }
        }

    }

    cout << "--------------------------------------------------" << endl;
    cout << "Dealer " << endl;
    dealer[0].displayHand();
    while (dealer[0].getHandTotal() < 17) {
        dealer[0].dealCard();
        cout << "--------------------------------------------------" << endl;
        cout << "New dealer hand" << endl;
        dealer[0].displayHand();
        cout << endl;
        Sleep(1000);
        if (dealer[0].checkBust() == true) {
            cout << "Dealer Bust!" << endl;
        }
    }


}

int newGame::checkWin(int i) {

    win = 0;
    if (hands[i].getHandTotal() > dealer[0].getHandTotal() && hands[i].getHandTotal() < 22 || dealer[0].getHandTotal() > 21 && hands[i].getHandTotal() < 22) {
        cout << "Player " << hands[i].playNo << " Wins!!" << endl;
        if (doubleDown == "y") {
            win = 5;
        }
        else {
            win = 1;
        }
    }
    else if (hands[i].getHandTotal() < dealer[0].getHandTotal() && dealer[0].getHandTotal() < 22 || hands[i].getHandTotal() > 21 && dealer[0].getHandTotal() < 22) {
        cout << "Dealer wins against player " << hands[i].playNo << "!!" << endl;
        if (doubleDown == "y") {
            win = 4;
        }
        else {
            win = 2;
        }

    }
    else if (hands[i].getHandTotal() > 21 && dealer[0].getHandTotal() > 21 || hands[i].getHandTotal() == dealer[0].getHandTotal()) {
        cout << "Player " << hands[i].playNo << " Draws" << endl;
        win = 3;
    }

    if (split = true) {
        for (auto ele : splitHands) {
            if (ele.No == hands[i].playNo) {
                if (splitHands[hands[i].playNo - 1].getHandTotal() > dealer[0].getHandTotal() && splitHands[hands[i].playNo - 1].getHandTotal() < 22 || dealer[0].getHandTotal() > 21 && splitHands[hands[i].playNo - 1].getHandTotal() < 22) {
                    cout << "Player " << hands[i].playNo << " Split hand wins!!" << endl;
                    win += 4;
                }
                else if (splitHands[hands[i].playNo - 1].getHandTotal() < dealer[0].getHandTotal() && dealer[0].getHandTotal() < 22 || splitHands[hands[i].playNo - 1].getHandTotal() > 21 && dealer[0].getHandTotal() < 22) {
                    cout << "Dealer wins against player " << hands[i].playNo << " Split hand!!" << endl;
                    win += 2;

                }
                else if (splitHands[hands[i].playNo - 1].getHandTotal() > 21 && dealer[0].getHandTotal() > 21 || splitHands[hands[i].playNo - 1].getHandTotal() == dealer[0].getHandTotal()) {
                    cout << "Player " << hands[i].playNo << " Split hand draws" << endl;

                }
            }
        }
    }


    return win;


}

bool newGame::playAgain(vector<bet> bets) {
    string again;

    bool cont = false;
    while (!cont) {
        try {
            cout << "Would you like to Play again? (y/n) " << endl;
            cin >> again;
            if (again == "y" || again == "n") {
                cont = true;
            }
            else {
                throw(again);
            }
        }
        catch (string again) {
            cout << "Input must be 'y' or 'n'" << endl;
        }
    }
    if (again == "y") {
        for (int i = 0; i < hands.size(); i++) {
            hands[i].resetHand();
            return true;
        }
    }
    else {
        cont = false;
        string save;
        for (int i = 0; i < hands.size(); i++) {
            while (!cont) {
                try {
                    cout << "Would you like to save your money player " << hands[i].playNo << "? (y/n)" << endl;
                    cin >> save;
                    if (save == "y" || save == "n") {
                        cont = true;
                    }
                    else {
                        throw(save);
                    }
                }
                catch (string save) {
                    cout << "Input must be 'y' or 'n'" << endl;
                }
            }
            if (save == "y") {
                string input;
                vector<string> playerBalances;
                bool found = false;
                string name;
                cont = false;

                while (!cont) {
                    try {
                        cout << "Whats your name? " << endl;
                        cin >> name;
                        if (any_of(name.begin(), name.end(), isdigit)) {
                            throw(name);
                        }
                        else {
                            cont = true;
                        }
                        cont = false;
                        ifstream file("playersMoney.txt");
                        playerBalances = {};
                        while (file >> input) {
                            playerBalances.push_back(input);
                        }
                        int c = 0;
                        for (int c = 0; c < playerBalances.size(); c++) {

                            if (playerBalances[c] == name) {
                                found = true;
                                cont = true;
                                playerBalances[c + 1] = to_string(bets[i].balance);
                            }
                        }
                        if (found == false) {
                            throw(found);
                        }

                        ofstream moneyFile("playersMoney.txt");
                        for (auto ele : playerBalances) {
                            moneyFile << " " << ele;
                        }
                        if (found == false) {
                            ofstream moneyFile("playersMoney.txt", ios::app);
                            moneyFile << " " << name << " " << bets[i].balance;
                        }
                    }
                    catch ([[maybe_unused]] bool found) {
                        cout << "No such username exists" << endl;
                    }

                    catch (string name) {
                        cout << "Enter a name not a number" << endl;
                        cin.clear();
                        cin.ignore(256, '\n');
                    }
                }
            }
        }

        return false;

    }


}


This is the header file:

#pragma once
#include <vector>
#include <string>

class cards {
public:
    std::vector<std::string> deck = { "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S","10S", "JS", "QS", "KS", "AS", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "10C", "JC", "QC", "KC", "AC","2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "KH", "AH", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD", "KD", "AD" };
    std::vector<std::string> shuffledDeck;
    inline cards();
    void shuffleDeck();
};

class hand : public cards {
public:

    std::vector<std::string> playerHand;
    int playNo;
    int handTotal;
    hand(int PlayNo);
    void dealCard();
    void displayHand();
    void resetHand();
    int getHandTotal();
    bool checkBust();
    std::vector<std::string> getHand();
    std::vector<std::string> split();
};

class dealerHand : public hand {
public:
    int No;

    inline dealerHand(int no);
    std::vector<std::string> getOrgHand();
    void dealerHit();
};

class splitHand : public hand {
public:
    int No;
    inline splitHand(int no, std::vector<std::string> hand);
       
    
};

class bet {
public:
    int balance = 100;
    int betAmount;
    void setBet();
    void splitBet();
    int getBet();
    int getBalance();
    void changeBalance(int win);

};

class newGame {
private:
    std::vector<hand> hands;
    int noOfPlayers;
    std::vector<dealerHand> dealer;
    std::vector<splitHand> splitHands;
    int dealerTotal;
    int win;
    bool split = false;
    std::string doubleDown;
    bool cont = false;
public:
    newGame(int NoOfPlayers);
    void dealCards(std::vector<bet> bets);
    void hitOrStand();
    int checkWin(int i);
    bool playAgain(std::vector<bet> bets);

};





any help would be appreciated.

0 Answers0