每当我尝试在Player类中包含 Hand 对象时,我都会收到以下错误。一旦调用 Player 类的构造函数,它就会显示以下错误消息:
架构x86_64的未定义符号: “ Hand :: Hand()”,引自: 在player-939de2中 Player :: Player()。 ld:找不到架构x86_64的符号
Player.h
#ifndef h_player
#define h_player
#include <string>
#include "hand.h"
using namespace std;
class Player{
private:
Hand* hand;
string name;
public:
Player();
void setName(string);
void setHand(Card);
string print() const;
void showHand() const;
};
#endif
Player.cpp
#include <iostream>
#include <string>
#include "player.h"
#include <iomanip>
using namespace std;
Player::Player() {
name = "";
hand = new Hand();
//std::cout<< "here";
}
void Player::setName(string name) {
this->name = name;
}
string Player::print() const {
return this->name;
}
void Player::setHand(Card add) {
hand->addCard(add);
}
void Player::showHand() const {
for(int i = 0; i < 7; i++) {
Card myCard = hand->showCard();
std::cout << "|" << std::setfill(' ') << std::setw(18) << std::right << myCard.print() << std::setfill(' ') << std::setw(18) << std::right << "|" << std::endl;
}
}
Hand.h
#ifndef h_hand
#define h_hand
#include <string>
#include "card.h"
using namespace std;
const int number_of_cards = 7;
class Hand {
private:
Card *cards;
int no_of_books;
int cards_remaining;
public:
Hand();
void addCard(Card);
bool checkHand();
Card showCard() const;
void withdraw();
};
#endif
Hand.cpp
#include <iostream>
#include <string>
#include "hand.h"
using namespace std;
Hand::Hand() {
cards = new Card[7];
cards_remaining = 7;
no_of_books = 0;
}
void Hand::addCard(Card add) {
if(cards_remaining > 0) {
cards[cards_remaining] = add;
cards_remaining--;
}
}
Card Hand::showCard() const {
return cards[cards_remaining++];
}