iterator가있는 사용자 지정 STL 호환 컨테이너를 구현하려는 것은 처음이지만 템플릿 구문 및 사용법에 문제가 있습니다.기본 매개 변수가있는 C++ 템플릿
namespace unstd {
template<typename T,class Allocator = std::allocator<T>>
class SList
{
public:
typedef typename Allocator::value_type value_type;
typedef typename size_t size_type;
typedef typename Allocator::template rebind<T>::other allocator_type;
typedef typename Allocator::reference reference;
typedef typename Allocator::const_reference const_reference;
typedef typename T* pointer;
typedef typename const T* const_pointer;
typedef typename ptrdiff_t difference_type;
typedef typename SList_Iterator_Forward<T> iterator;
typedef typename const SList_Iterator_Forward<T> const_iterator;
....
/*----- ITERATORS -------*/
iterator begin();
...
};}
가의 시작 예를 들어 살펴 보자() 메소드 : 이 내 헤더 파일의 일부입니다. 내가 쓴 컴파일하지 않는다 (A .cpp 파일에서) 다음
template<typename T, class Allocator>
iterator SList<T,Allocator>::begin()
{
}
//neither the following compile
template<typename T, class Allocator>
SList<T,Allocator>::iterator SList<T,Allocator>::begin()
{
}
을 나는 몇 가지 질문이 있습니다
- 이 컴파일되지 않습니다 왜? (오류 C2143 구문 오류 : 'token2'앞에 'token1'이 없습니다.)
- 왜 모든 템플릿 매개 변수를 명시 적으로 지명해야합니까? (즉, Allocator가 기본값을 가지고 있다는 점을 감안할 때 T 만 지정할 수는 없습니까?)
- 이 상황에서 구현 헤더를 분리하는 것이 옳은가요? 몇 가지 이유를 들어
_STL은 (는) C++ 표준 라이브러리가 아닙니다. – Griwes
해당 오류 메시지는 코드 –