내 질문은 다른 템플릿의 매개 변수 일 때 템플릿의 "형식"을 지정해야합니까? 이것은 전문화 된 방법입니다.클래스 템플릿 인 클래스 템플릿 메서드의 특성화 템플릿 오류 : 형식/값이 일치하지 않는 경우 인수가
당신을 문맥에 넣을 수있게하십시오.
템플릿 컴퓨터 클래스가있는 TicTacToe 게임을하고 있습니다. 그래서, 난 매개 변수에 어려움 수준을 설정할 수 있습니다. 이 그것의 샘플입니다
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를 사용하여 ticTacToe 클래스를 생성하는 아이디어를 내놓았다 때문에 매개 변수는 플레이어의 다른 유형을받습니다. 이것은 샘플입니다. 내가 올바른 문법을 설정하는 문제가 발생, 그래서 컴파일러는 나를 이해 :
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.
*/
}
내 질문에 반환. 조직
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