0

I'm making a simple go fish card game. When I try to build the program, an error message pops up that the symbols for the system architecture have been undefined but I'm most certain I defined them.

gofish.cpp:

void GoFish::addcard(string suit, int Value)
{
    card* temp = new card;
    temp->suit = suit;
    temp->Value = Value;
    deck.push_back(temp);
}


void GoFish::addcard(string suit, int Value)
{
    card* temp = new card;
    temp->suit = suit;
    temp->Value = Value;
    deck.push_back(temp);
}

void GoFish::ShuffleDeck()
{
    srand(unsigned(time(0)));
    random_shuffle(deck.begin(), deck.end());
    CardsShuffled = true;
}

void GoFish::DealCards()
{
    int counter = 0;

    for (counter = 0; counter < 14; counter++)
    {
        if (counter == 0)
        {
            UserRoot = deck.back();

            deck.pop_back(); //Removes the card from the deck
        }

        else if (counter == 1)
        {
            CPURoot = deck.back();
            deck.pop_back();
        }

        else if (counter%2 == 0)
        {
            card* temp = deck.back();
            deck.pop_back();
            AddToHand("User", temp);
        }

        else
        {
            card* temp = deck.back();
            deck.pop_back();
            AddToHand("CPU", temp);
        }
    }
    CardsDealt = true;
}

void GoFish::DisplayCards()
{
    card* temp = UserRoot;
    cout << "Your cards are: " << endl;

    while (temp != NULL)
    {
        if (temp->Value == 1)
        {
            cout << "Ace of " << temp->suit << endl;
        }
        else if (temp->Value == 11)
        {
            cout << "Jack of " << temp->suit << endl;
        }
        else if (temp->Value == 12)
        {
            cout << "Queen of " << temp->suit << endl;
        }
        else if (temp->Value == 13)
        {
            cout << "King of " << temp->suit << endl;
        }
        else 
        {
            cout << temp->Value << " of " << temp->suit << endl;
        }
        temp = temp->next;
    }
    CardsDisplayed = true;
}

void GoFish::SearchCards(string User, int value)
{
    vector <card*> UserDeckTemp;

    bool FoundCard1 = false;
    bool FoundCard2 = false;

    if (User == "User")
    {
        card* head = CPURoot;

        while (head != NULL)
        {
            if (head->Value == value)
            {
                FoundCard1 = true;
                DeleteCards("CPU", value);
                cout << "Card/Cards found!" << endl;
                break;
            }
            head = head->next;
        }

        if (FoundCard1 == false)
        {
            cout << "CPU does not have that card. Pulling card from pile!" << endl;
            card* tempr = deck.back();
            deck.pop_back();
            AddToHand("User", tempr);
        }
    }
}

int main(int argc, char** argv) {




    return 0;
}

gofish.h:

#ifndef GOFISH_H
#define GOFISH_H

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

using namespace std;

struct card
{
    int Value;
    string suit;
    card* next = NULL;
    card* prev = NULL;

};

class GoFish {

private:
    vector <card*> deck;
    card* UserRoot = NULL;
    card* CPURoot = NULL;

public:

    GoFish();

    // Using a destructor to erase cards when chosen 
    virtual ~GoFish();

    void addcard(string, int);

    void ShuffleDeck();

    void DealCards();

    void DisplayCards();

    void SearchCards(string User, int value);

    void DeleteCards(string User, int value);

    void AddToHand(string User, card* temp);

    void RemoveBook(std::string User, int value);

    int userMax(std::string user, card* userRoot);
    card *getUserRoot(std::string player);
    bool isEmpty();
    bool inUserHand(int);
    bool CardsShuffled = false;
    bool CardsDealt = false;
    bool CardsDisplayed = false;
    bool GOver = false;
    int count1 = 0;
    int count2 = 0;

};

#endif  /* GOFISH_H */

The error:

Undefined symbols for architecture x86_64:
  "GoFish::DeleteCards(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int)", referenced from:
      GoFish::SearchCards(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int) in isp.o
  "GoFish::AddToHand(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, card*)", referenced from:
      GoFish::DealCards() in isp.o
      GoFish::SearchCards(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int) in isp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Devon Hope
  • 11
  • 2
  • The error messages are correct. It looks like you declared and used but did not implement `void DeleteCards(string User, int value)` same goes for `void AddToHand(string User, card* temp)` – drescherjm May 29 '16 at 14:23
  • How would I properly implement them? Sorry kind of new to programming – Devon Hope May 29 '16 at 15:11
  • I say that is really not how Stack Overflow works. You need to implement the functions and when you get stuck you can ask questions about your implementation of these functions and why your implementation does not work as you expect. – drescherjm May 29 '16 at 17:04

0 Answers0