【发布时间】:2019-10-30 02:10:33
【问题描述】:
这个问题之前已经解决了,但是我一直在寻找,没有一个解释如何解决这个问题,我所处的情况。大多数是关于外部库的。
我正在尝试测试我的代码。我已经创建了一个测试类,并且该类试图通过包含该类的头文件来访问另一个类。但是当我试图调用它的函数时,它只会给我一个未解决的外部符号错误。
这是我目前的尝试。这里我试图访问其他类的头文件来调用它的函数。
CardTest.cpp
#include <iostream>
#include "../Header Files/Hand.h"
#include "../Header Files/HandValueCalculator.h"
using namespace std;
HandValueCalculator handValueCalculator;
Hand hand;
void Test() {
bool value = handValueCalculator.DoesHandHaveAce(&hand.cards);
cout << value << endl;
}
HandValueCalculator.h
#ifndef HANDVALUECALCULATOR_H_INCLUDED
#define HANDVALUECALCULATOR_H_INCLUDED
#include <vector>
#include "../Header Files/Card.h"
class HandValueCalculator {
public:
HandValueCalculator();
bool DoesHandHaveAce(std::vector<Card>* cards);
int GetValueWithoutAce(std::vector<Card>* cards);
int GetValueWithAce(std::vector<Card>* cards);
};
#endif // HANDVALUECALCULATOR_H_INCLUDED
HandValueCalculator.cpp
#include "../Header Files/HandValueCalculator.h"
HandValueCalculator::HandValueCalculator() {
}
bool HandValueCalculator::DoesHandHaveAce(std::vector<Card>* cards) {
int i;
for (i = 0; i < cards.size(); i++) {
if (cards.at(i).GetValue() == 11) {
return true;
}
}
return false;
}
int HandValueCalculator::GetValueWithoutAce(std::vector<Card>* cards) {
for (i = 0; i < cards.size(); i++) {
int cardValue = cards.at(i).GetValue()
totalValue = totalValue + cardValue;
}
return 0;
}
int HandValueCalculator::GetValueWithAce(std::vector<Card>* cards) {
return 0;
}
这是我遇到的错误,我认为编译器没有识别出函数有一个主体,并且因为它找不到声明的函数的主体,所以它会返回这样的错误。
C:\Users\fagel\Documents\Blackjack\Blackjack\CardTest.obj : error LNK2019: unresolved external symbol "public: void __thiscall HandValueCalculator::a(void)" (?a@HandValueCalculator@@QAEXXZ) referenced in function "void __cdecl Test(void)" (?Test@@YAXXZ)
【问题讨论】:
标签: c++ error-handling compiler-errors