私の質問は、別のテンプレートのパラメータである場合、テンプレートの "タイプ"を指定する必要がありますか?これはメソッドの特殊化である。クラステンプレートメソッドの特殊化クラステンプレートエラー:型/値の不一致での引数
私は文脈であなたを置くことを許可しましょう。
私はTicTacToeゲームをやっています.TicTacToeゲームでは、テンプレートComputerクラスがあります。だから、私はパラメータの難易度を設定することができます。 これはサンプルです:
template<int T>
class Computer
{
Node *Root; /**< Root of a decision tree */
Node *Current; /**< Current node in a decision tree*/
int PlayerNumber; /**< Player ID*/
int OponnentNumber /**< Opponent ID*/
Public:
/**< Constructor destructor */
int refreshBoard(int move);
int play()const; /**< This methods has different implementations, for each level of difficulty*/
}
はその後、私はtempated三目並べクラスを作成するためにアイデアを思い付いたので、パラメータは、プレイヤーのさまざまな種類を受けます。 これはサンプルです。
template <typename T1, typename T2>
class TicTacToe
{
T1 &Player1; /**< Simulates the first player */
T2 &Player2; /**< Simulates the second player */
Board &b__; /**< Simulates a board */
int TurnCounter;
public:
int newTurn();
/* This method is implemented differently for each type of combination of player
* Lets say player 1 is Human and player 2 is computer. The new turn will
* change the state of the board and will return 1 if there is still new turns
* to come.
*/
}
私の質問に戻る:私は正しい文法を設定する際に問題を抱えているので、コンパイラは私を理解しています。
それはerrosたくさん返す:組織
template<>
int TicTacToe<Human,Computer>::newTurn()
...implementation
このタイプの
error: type/value mismatch at argument 2 in template parameter list for ‘template<class T1, class T2> class TicTacToe’
int JogoVelha<Human,Computer>::newTurn()`
note: expected a type, got ‘Computer’
header/TicTacToe.h:201:40: error: ‘newTurn’ is not a template function
int TicTacToe<Human,Computer>::newTurn()
をそして、私は理由を理解することはできません。あなたの助けが必要です。
のようにそれを使うのか?それ以外の場合は、HumanPlayerクラスとComputerPlayerクラスで実装されているPlayerインターフェイスを使用するだけで、ここでテンプレートを使用する利点は実際にはわかりません。 –
私が始めたときのプロジェクトの決定でした。私が気づいたのは、それが最善の選択ではなかったことです。しかし、あなたのアイデアは私の心の中には来なかったし、それはもっと直接的で簡単です。あなたが気にしないなら、私はあなたが言ったことを私の戦艦プロジェクトを構築するために使用する – Homunculus