这是我一直在研究的一个程序的摘录。我怀疑问题可能是由 Player 类的这个成员引起的:
std::vector<std::list<Bid> > lBidding
该代码导致以下构建错误:
g++ -o ./Debug/fudge @"/Users/andvik/MockUp/fudge/fudge.txt"-L.
Undefined symbols for architecture x86_64:
"Player::lBidding", referenced from:
Deal::bidding() in MockUp_main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [Debug/fudge] Error 1
make[1]: Leaving directory `/Users/andvik/MockUp/fudge'
make: *** [All] Error 2
make: Leaving directory `/Users/andvik/MockUp'
----------Build Ended----------
0 errors, 0 warnings
我很有信心这个错误与静态向量有关,因为那是我添加的最后一段代码。我的研究表明许多不同的问题会导致类似的错误,但它们似乎都与我拥有的相同类型的代码无关。
代码:(我已经删除了几行似乎不适用的代码。这应该是最低限度的。)
#include <string>
#include <list>
#include <vector>
class Bid
{
public:
short iLevel;
short iSuit;
Bid():iLevel(0),iSuit(0){};
Bid(short l, short s):iLevel(l),iSuit(s){};
bool operator ==(const Bid Other) const
{
if(iLevel==Other.iLevel && iSuit==Other.iSuit)
{return 1;}
else{return 0;}
}
};
class Player
{
public:
short iPos;
static std::vector<std::list<Bid> > lBidding;
Player(short p):iPos(p) {};
bool operator ==(const Player Other) const
{
if(iPos == Other.iPos){return 1;}
else{return 0;
}
}
};
class Deal
{
public:
short iPass;
short iIteration;
Player pWest, pNorth, pEast, pSouth, pError;
Deal(): iPass(0), iIteration(0), pWest(0), pNorth(1), pEast(2), pSouth(3), pError(5){};
void bidding()
{
Player pTemp(5);
Bid bTemp, bPass;
while(iPass < 3)
{
pTemp = setPlayer();
if(pTemp == pError){break;}
if(Player::lBidding.at((pTemp.iPos+2)%4).empty()){}
else
{
if(Player::lBidding.at(pTemp.iPos).empty()){}
}
if(bTemp == bPass){++iPass;}
else{(*Player::lBidding.begin()).push_back(bTemp);}
};
}
Player setPlayer()
{
switch(iIteration % 4)
{
case 0: return pWest; break;
case 1: return pNorth; break;
case 2: return pEast; break;
case 3: return pSouth; break;
}
return pError;
}
};
int main(int argc, char **argv)
{
srand(time(0));
Deal deal;
deal.bidding();
printf("No debugging error.\n");
return 0;
}
所以有人可以告诉我,我的代码有什么问题以及为什么。顺便说一句,如果有人想知道这构成了一种自制桥模拟器的大部分内容。