我正在尝试解决ProjectEuler上的问题54。对于那些不熟悉它的人来说,它需要找到1000场扑克游戏的胜利者。
我遇到的问题是,当我尝试使用typedef使我的程序更简单易读时,我遇到了以下问题。
错误
pokerchecker.hpp:37: error: expected unqualified-id before '[' token
pokerchecker.hpp:38: error: ISO C++ forbids declaration of 'Hand' with no type
接下来是许多其他错误,但它们似乎是由上述原因造成的。
第37行如下
typedef Card[5] Hand;
完整标题
#ifndef POKERCHECKER_HPP
#define POKERCHECKER_HPP
class PokerChecker{
public:
PokerChecker(){};
~PokerChecker(){};
enum Rank{
TWO = 2,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING,
ACE
};
enum Suit{
HEART,
DIAMOND,
CLUB,
SPADE
};
struct Card{
Rank rank;
Suit suit;
};
typedef Card[5] Hand; // line 37
typedef Hand[2] PokerGame;
typedef short Winner;
Winner EvaluateGame(PokerGame unsortedGame);
private:
PokerGame SortGame(PokerGame unsortedGame);
Hand SortHand(Hand);
// each function returns the highest card (for comparing two similar hands)
Card CheckRF(Hand);
Card CheckSF(Hand);
Card CheckFOAK(Hand);
Card CheckFH(Hand);
Card CheckF(Hand);
Card CheckS(Hand);
Card CheckTOAK(Hand);
Card CheckTP(Hand);
Card CheckOP(Hand);
Card CheckHC(Hand);
};
#endif //POKERCHECKER_HPP
我想做的是什么?如果是这样,我当前的代码有多么错误?
答案 0 :(得分:10)
声明数组typedef的正确方法是:
typedef Card Hand[5];