错误:“架构x86_64的未定义符号”

时间:2016-05-29 13:38:01

标签: c++

我正在做一个简单的去鱼卡游戏。当我尝试构建程序时,会弹出一条错误消息,表明系统架构的符号未定义,但我确定我已定义它们。

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 */

错误:

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)

0 个答案:

没有答案