可能重複:
What is an undefined reference/unresolved external symbol error and how do I fix it?無法解析的外部[構造]
我與鏈接一個問題,我解決不了.. 已經嘗試過任何我能想到的 我有一個Baseclass(Person)和派生類(Dealer),我只想從CardStack類中調用構造函數,這是Dealer類中的成員。
這裏是我的代碼:
Person.h
#ifndef PERSON_H
#define PERSON_H
#include "Card.h"
#include "Hand.h"
class Person
{
public:
Person(void);
virtual ~Person(void);
virtual bool TakeCard(Card c);
virtual bool Lost(void);
protected:
virtual void CheckLost(void);
bool b_Lost;
Hand m_Hand;
};
#endif
Dealer.h
#ifndef DEALER_H
#define DEALER_H
#include "Person.h"
#include "Card.h"
#include "CardStack.h"
class Dealer : public Person
{
public:
Dealer(int stackcount);
virtual ~Dealer(void);
bool TakeCard(Card c);
bool Lost(void);
Card GiveCard(Card c);
protected:
void CheckLost(void);
CardStack m_GameStack;
};
#endif
Dealer.cpp
#include "Dealer.h"
Dealer::Dealer(int stackcount) : Person(), m_GameStack(stackcount)
{
};
Dealer::~Dealer(void)
{
};
bool Dealer::TakeCard(Card c)
{
if(!b_Lost || m_Hand.GetTotal() <= 17)
{
m_Hand.Take(c);
CheckLost();
return true;
}
return false;
};
void Dealer::CheckLost()
{
if (m_Hand.GetTotal() > 21)
{
b_Lost = true;
}
};
bool Dealer::Lost()
{
return b_Lost;
};
老實說,我試過寄託都我能想到的但我無法確定出了什麼錯誤是...
以下是編譯Dealer.cpp當輸出:
1> Dealer.obj:錯誤LNK2019:無法解析的外部符號「市民:虛擬__thiscall人::〜人(無效)「(?? 1Person @@ UAE @ XZ)函數引用__unwindfunclet $ ?? 0Dealer @@ QAE @ H @ Z $ 0
1> Dealer.obj:錯誤LNK2001:無法解析的外部符號」public:virtual bool __thiscall Person :: TakeCard(class Card)「(?TakeCard @ Person @@ UAE_NVCard @@@ Z)
1> Dealer.obj:error LNK2001:無法解析的外部符號」public:virtual bool __thiscall Person :: Lost(void)「(?Lost @ Person @@ UAE_NXZ)
1> Dealer.obj:error LNK2001:無法解析的外部符號」protected:virtual void __thiscall Person :: CheckLost(void)「(?CheckLost @ Person @@ MAEXXZ)
鏈接器告訴你到底什麼是錯的。見http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix/12574407#12574407 –
所以它只是虛擬析構函數讓我陷入困境? 對不起,如果它的重複我看了很多外部符號錯誤,但沒有匹配我的:( – TheSentry
,但我已經在經銷商::經銷商() 實施虛擬析構器哦,明白了!聲明構造純粹^^你:) – TheSentry