을 사용하고 내가 뭔가를 알아낼 수 없을 때 나는 키워드 "유형 이름"을 사용해야 할 때 ..나는 작은 프로젝트에 최근에 일한지 템플릿
나는 .H 파일을 주어 졌어 그 typename 템플릿을 사용하여 클래스를 포함하고있었습니다. 그 수업 안에는 개인 수업이있었습니다. 나는 그래서
template<typename T>
Node* Something::Function1(int index) //Is the return type well written?
{
// returns the node at the specified index
}
template<typename T>
int Something::Index(const T& id) //Is the parameter type well specified?
{
// returns the index of the node with the specified id
}
도청 (A .inl 파일) 클래스 "뭔가"
여기내가 그 일을했다 방법의 함수를 정의하고 싶어 할 때
template <typename T>
class Something
{
public:
Something();
~Something();
Node* Function1(int index);
int Index(const T& id);
private:
class Node()
{
public:
T id;
//Imagine the rest for the Node
};
};
는 문제가 발생했습니다 part가 definition 부분에 있습니다 ... 반환 유형 (이 경우 Node *)이 typename 템플릿 (예 : typename Node*
)을 사용한다는 것을 컴파일러에 알려야합니까? 그리고 매개 변수는 어떻습니까? typename const Node&
?
그래서 기본적으로 함수/매개 변수가 템플릿을 사용하는 경우를 지정해야합니까?
감사합니다.
귀하의 질문에 sinppets 게시물하십시오! – mmmmmmmm
스 니펫과 링크를 게시했습니다. 내 스 니펫을 정확하게 들여 쓰는 방법을 알아낼 수 없었습니다. – Pacane